0
嗨在我的項目中,我正在使用自定義適配器。當包含列表視圖的活動打開時,圖像視圖和文本視圖首先出現,然後一段時間視圖消失。我找不到解決方案嗎? 編輯: 它也適用於模擬器,但不工作在普通設備上?視圖後從列表視圖消失
其中i設置適配器類:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_person_deatil);
Intent detailIntent = getIntent();
Gson gson = new Gson();
String obj = detailIntent.getStringExtra("obj");
PeopleListItem people = gson.fromJson(obj, PeopleListItem.class);
ListView lw = (ListView) findViewById(R.id.perdetLw);
PeopleListItem[] list = new PeopleListItem[6];
for(int i=0; i<6; i++){
list[i] = people;
}
ActionBar ab = getActionBar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setTitle(people.getName());
ab.setIcon(R.drawable.ic_action_person);
PeopleDetailArrayAdapter adp = new PeopleDetailArrayAdapter(this, R.layout.person_detail_item, list);
lw.setAdapter(adp);
}
類的定製適配器的:
public class PeopleDetailArrayAdapter extends ArrayAdapter<PeopleListItem> {
int resource;
Context context;
int count = 0;
public PeopleDetailArrayAdapter(Context context, int resource,
PeopleListItem[] list) {
super(context, resource, list);
this.resource = resource;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
final PeopleListItem peopleObj = getItem(position);
LayoutInflater layoutInflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View listViewItem = layoutInflator.inflate(resource, null);
final TextView textView = (TextView) listViewItem.findViewById(R.id.detailTw);
final TextView textView1 = (TextView) listViewItem.findViewById(R.id.detailTw1);
final ImageView imageView = (ImageView) listViewItem.findViewById(R.id.detailIw);//img view kişinin resmine göre değişmeli
final ImageView imageView1 = (ImageView) listViewItem.findViewById(R.id.detailIw1);
switch (count) {
case 0:
textView.setText("Title:");
String title = peopleObj.getTitle();
textView1.setText(title);
break;
case 1:
textView.setText("Department:");
String dep = peopleObj.getDepart();
textView1.setText(dep);
break;
case 2:
textView.setText("Work Phone:");
String wp = peopleObj.getWorkPhone();
textView1.setText(wp);
imageView.setVisibility(ImageView.VISIBLE);
break;
case 3:
textView.setText("Mobile Phone:");
String mp = peopleObj.getMobilePhone();
textView1.setText(mp);
imageView.setVisibility(ImageView.VISIBLE);
imageView1.setVisibility(ImageView.VISIBLE);
break;
case 4:
textView.setText("Email:");
String email = peopleObj.getEmail();
textView1.setText(email);
break;
case 5:
textView.setText("Manager:");
String man = peopleObj.getManager();
textView1.setText(man);
break;
default:
break;
}
count++;
return listViewItem;
}
}
爲什麼你把'list'的所有元素都賦給同一個'people'變量? – mangusta
不要爲創建佈局而浪費時間,我會爲包含所有需要的行創建一個簡單的佈局。 – calypso
你可以使用** ViewHolder **模式來獲得更好的性能。 – Piyush