getView不呈現我正在處理android ListView
和我面臨奇怪的錯誤當我充氣ListItem
。即使數據已在LogCat
中顯示,我也無法在getView
方法中看到我的數據。有任何想法嗎 ?即使數據顯示在LogCat
private ListViewAdapter m_adapter;
public ArrayList<String> cat = new ArrayList<String>();
private SharedPreferences preferences;
private SharedPreferences.Editor editor;
String title, character, thumbnail, totalPages;
int Code;
ViewHolder vh;
TextView titleView, charView, totalView;
ImageView thumbView, removeView;
Uri thumbUri;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Black_NoTitleBar);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.myputet);
init_UI();
}
public void init_UI() {
preferences = getApplicationContext().getSharedPreferences(
Constants.SHARED_PRED, 0);
editor = preferences.edit();
title = preferences.getString("TITLE", "");
character = preferences.getString("CHAR", "");
thumbnail = preferences.getString("THUMB", "");
thumbUri = Uri.parse(thumbnail);
totalPages = preferences.getString("TOTAL", "");
Code = preferences.getInt("CODE", 0);
System.out.println("Getting Title " + title);
System.out.println("Getting character " + character);
System.out.println("Getting thumbnail " + thumbnail);
System.out.println("Getting thumbUri " + thumbUri);
System.out.println("Getting totalPages " + totalPages);
Log.v("ArrayList", cat.toString());
ListView lv = (ListView) findViewById(R.id.listview);
m_adapter = new ListViewAdapter(this, R.layout.myputet_item, cat);
lv.setAdapter(m_adapter);
}
private class ListViewAdapter extends ArrayAdapter<String> {
private ArrayList<String> items;
public ListViewAdapter(Context context, int textViewResourceId,
ArrayList<String> items) {
super(context, textViewResourceId, items);
this.items = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.myputet_item, null);
}
Log.v("Title View", title);
titleView = (TextView) v.findViewById(R.id.titleTxtView);
charView = (TextView) v.findViewById(R.id.charTxtView);
totalView = (TextView) v.findViewById(R.id.totalTxtView);
thumbView = (ImageView) v.findViewById(R.id.charImageView);
removeView = (ImageView) v.findViewById(R.id.removeListItem);
if (titleView != null) {
titleView.setText(title);
Log.v("Update Title", title);
}
charView.setText(character);
Log.v("Update character", character);
totalView.setText(totalPages);
Log.v("Update totalPages", totalPages);
thumbView.setImageURI(thumbUri);
return convertView;
}
}
LogCat
輸出
10-31 23:52:34.438: V/Title View(4568): မိခ်ိဳေစ်းကအျပန္
10-31 23:52:34.438: V/Update Title(4568): မိခ်ိဳေစ်းကအျပန္
10-31 23:52:34.438: V/Update character(4568): ကိုေရႊထူး(ျပည္)
10-31 23:52:34.438: V/Update totalPages(4568): 3
http://www.youtube.com/watch?v=wDBM6wVEO70。這應該可以幫助你解決你的問題。 – Raghunandan