也許,有人可以給我一些原因,這不順心.. 我想學習這個教程 (http://sudarmuthu.com/blog/using-arrayadapter-and-listview-in-android-applications/) 但我想將此自定義適配器。 。無法在ArrayAdapter達到getView <>
menuListList.setAdapter(new ArrayAdapter<String>(MenuListActivity.this, R.layout.menu_list){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (convertView == null){
row = getLayoutInflater().inflate(R.layout.menu_list, null);
} else {
row = convertView;
}
Log.w("tes", "te3s");
TextView menuListTitle = (TextView) row.findViewById(R.id.menuListTitle);
menuListTitle.setText(titleList[position]);
return row;
}
});
我之前和menuListList.setAdapter(後到達日誌),但我不能趕上日誌裏面和我的ListView(menuListList)變成空白
這是我的WH OLE類
public class MenuListActivity extends AppCompatActivity {
ListView menuListList;
String[] titleList = {
"Purchase Order",
"Receive Item",
"Expired Item"
};
Integer[] imageList = {
R.drawable.po,
R.drawable.ri,
R.drawable.ex
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_list);
menuListList = (ListView)findViewById(R.id.menuListList);
Log.w("tes", "tes1");
menuListList.setAdapter(new ArrayAdapter<String>(MenuListActivity.this, R.layout.menu_list){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
if (convertView == null){
row = getLayoutInflater().inflate(R.layout.menu_list, parent, false);
} else {
row = convertView;
}
Log.w("tes", "te2s");
TextView menuListTitle = (TextView) row.findViewById(R.id.menuListTitle);
menuListTitle.setText(titleList[position]);
return row;
}
});
Log.w("tes", "te3s");
}
}
我能達到 「TES1」 和 「te3s」 的log.w但不是 「te2s」
粘貼完整的類,我們可以幫助你。 –
你在擴展listActivtiy嗎? –
哪裏是適配器的數據源?傳遞數組titleList作爲ArrayAdapter構造函數中的第三個參數https://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context,int,T []) – Raghunandan