gpt4 book ai didi

android - 在数组适配器中省略空 View

转载 作者:行者123 更新时间:2023-11-29 02:08:25 25 4
gpt4 key购买 nike

我的数组适配器是这样的:

http://www.airbrush-ernst.nl/domo1.jpg

我不允许发布图片 :(

我也想省略空 View 。我刚开始使用 android,我试图操纵 getview,但这不起作用。

谁能帮帮我。

谢谢

这是我的代码

    public class MyCustomAdapter extends ArrayAdapter<String> {

public MyCustomAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// return super.getView(position, convertView, parent);

View row = convertView;


if (row == null) {
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.row, parent, false);

}

TextView label = (TextView) row.findViewById(R.id.rowText);
label.setText(locatie[position]);
ImageView icon = (ImageView) row.findViewById(R.id.icon);

if (position == 0 && on1) {
icon.setImageResource(R.drawable.bulpon);
} else if (position == 1 && on2) {
icon.setImageResource(R.drawable.bulpon);
} else {
icon.setImageResource(R.drawable.bulpoff);
}

return row;

}
}




String[] locatie = { "Huiskamer - achter TV", "Huiskamer - kast",
"Huiskamer - achter", "Keuken", "Voordeur", "", "", "", "",
"", "" };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

haaldata();
// setListAdapter(new MyCustomAdapter(Binnen.this, R.layout.row,
// locatie));

}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();

SharedPreferences getPrefs = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
String prefM1 = getPrefs.getString("menu1", "");
if (!prefM1.trim().contentEquals(""))
locatie[0] = prefM1;
String prefM2 = getPrefs.getString("menu2", "");
if (!prefM2.trim().contentEquals(""))
locatie[1] = prefM2;
String prefM3 = getPrefs.getString("menu3", "");
if (!prefM3.trim().contentEquals(""))
locatie[2] = prefM3;
String prefM4 = getPrefs.getString("menu4", "");
if (!prefM4.trim().contentEquals(""))
locatie[3] = prefM4;
String prefM5 = getPrefs.getString("menu5", "");
if (!prefM5.trim().contentEquals(""))
locatie[4] = prefM5;
String prefM6 = getPrefs.getString("menu6", "");
if (!prefM6.trim().contentEquals(""))
locatie[5] = prefM6;
String prefM7 = getPrefs.getString("menu7", "");
if (!prefM7.trim().contentEquals(""))
locatie[6] = prefM7;
String prefM8 = getPrefs.getString("menu8", "");
if (!prefM8.trim().contentEquals(""))
locatie[7] = prefM8;
String prefM9 = getPrefs.getString("menu9", "");
if (!prefM9.trim().contentEquals(""))
locatie[8] = prefM9;
String prefM10 = getPrefs.getString("menu10", "");
if (!prefM10.trim().contentEquals(""))
locatie[9] = prefM10;



setListAdapter(new MyCustomAdapter(Binnen.this, R.layout.row, locatie));

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.cool_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
super.onOptionsItemSelected(item);
switch (item.getItemId()) {
case R.id.aboutus:
Intent i = new Intent("nl.ernst.splash.ABOUT");
startActivity(i);

break;
case R.id.preferences:
Intent p = new Intent("nl.ernst.splash.PREFS");
startActivity(p);
break;
case R.id.exit:
finish();
break;

}
return false; // onOptionsItemSelected verwacht een boolean terug dus
// geef maar wat terug :-)
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
// super.onListItemClick(l, v, position, id);
String selection = l.getItemAtPosition(position).toString();
Toast.makeText(this, selection, Toast.LENGTH_SHORT).show();
}

private void haaldata() {
// TODO Auto-generated method stub
URL textUrl;
try {
textUrl = new URL(outSource);
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(textUrl.openStream()));
String StringBuffer;
String stringText = "";
while ((StringBuffer = bufferReader.readLine()) != null) {
stringText += StringBuffer;
}
bufferReader.close();

Toast.makeText(this, stringText, Toast.LENGTH_SHORT).show();

String str[] = stringText.split(",");
if (str[0].equals("1")) {
on1 = true;
} else {
on1 = false;
}

if (str[1].equals("1")) {
on2 = true;
} else {
on2 = false;
}

// msg.setText(stringText);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block e.printStackTrace();

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
}
}// class Binnen

最佳答案

在你的适配器中你想创建这个方法

public class MyCustomAdapter extends BaseAdapter{
...
public int getCount() {
return 5;//or however many you want to have total
}
...
}

关于android - 在数组适配器中省略空 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8694084/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com