您好我一直在尝试使用自定义列表项目布局的自定义列表活动,我迫切需要帮助。我用作列表适配器的自定义适配器类可能是错误的或者是正确的,但无论是什么方法,getView()都没有被使用,当我将日志放入其中时它没有显示,我的适配器类是这样的:
private class MyAdapter extends ArrayAdapter<String>{
int position1;
public MyAdapter(Context context, int resource,int pos) {
super(context, resource);
position1 = pos;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = inflater.inflate(R.layout.privatep_single_list_item, parent, false);
String[] general_Items = new String[Items.length()] ;
String[] financial_Items = new String[Items.length()] ;
String[] address_Items = new String[Items.length()] ;
StringBuilder general_sb = new StringBuilder();
StringBuilder financial_sb = new StringBuilder();
StringBuilder address_sb = new StringBuilder();
if(position1 == 0){
try{
for(int i = 0; i < Items.length(); i++){
general_sb.append(Items.getJSONObject(i).getString("Area").toString());
general_sb.append(" متر ");
general_sb.append(Items.getJSONObject(i).getString("Bedrooms").toString());
general_sb.append(" خواب ");
general_sb.append(Items.getJSONObject(i).getString("CA").toString());
general_sb.append(" ساخت ");
financial_sb.append("متری ");
financial_sb.append(Items.getJSONObject(i).getString("OPPM").toString());
financial_sb.append(" تومان");
address_sb.append(Items.getJSONObject(i).getString("address").toString());
general_Items[i] = general_sb.toString();
financial_Items[i] = financial_sb.toString();
address_Items[i] = address_sb.toString();
}}
catch (Exception e){
Log.e("Fail 3", e.toString());
}
} else if (position1 == 1){
try{
for(int i = 0; i < Items.length(); i++){
general_sb.append(Items.getJSONObject(i).getString("Area").toString());
general_sb.append(" متر ");
general_sb.append(Items.getJSONObject(i).getString("Bedrooms").toString());
general_sb.append(" خواب ");
general_sb.append(Items.getJSONObject(i).getString("CA").toString());
general_sb.append(" ساخت ");
financial_sb.append("کرایه ");
financial_sb.append(Items.getJSONObject(i).getString("Rent").toString());
financial_sb.append(" /n");
financial_sb.append("رهن ");
financial_sb.append(Items.getJSONObject(i).getString("PrePayment").toString());
address_sb.append(Items.getJSONObject(i).getString("address").toString());
general_Items[i] = general_sb.toString();
financial_Items[i] = financial_sb.toString();
address_Items[i] = address_sb.toString();
}}
catch (Exception e){
Log.e("Fail 3", e.toString());
}
} else if (position1 == 2){
try{
for(int i = 0; i < Items.length(); i++){
general_sb.append(Items.getJSONObject(i).getString("Area").toString());
general_sb.append(" متر ");
general_sb.append(Items.getJSONObject(i).getString("Bedrooms").toString());
general_sb.append(" خواب ");
general_sb.append(Items.getJSONObject(i).getString("CA").toString());
general_sb.append(" ساخت ");
financial_sb.append("رهن ");
financial_sb.append(Items.getJSONObject(i).getString("Price").toString());
address_sb.append(Items.getJSONObject(i).getString("address").toString());
general_Items[i] = general_sb.toString();
financial_Items[i] = financial_sb.toString();
address_Items[i] = address_sb.toString();
}}
catch (Exception e){
Log.e("Fail 3", e.toString());
}
}
TextView general_text = (TextView) row.findViewById(R.id.General_Info);
TextView financial_text = (TextView) row.findViewById(R.id.Financial_Info);
TextView address_text = (TextView) row.findViewById(R.id.Address_Info);
general_text.setText(general_Items[position]);
financial_text.setText(financial_Items[position]);
address_text.setText(address_Items[position]);
return super.getView(position, convertView, parent);
}
}
这是我的适配器构造
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.privatep);
setListAdapter(new MyAdapter(this,android.R.layout.simple_list_item_1,0));
Spinner spinner = (Spinner) findViewById(R.id.select_Spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.select_Options_personal, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
我将非常感谢您对此事的评论。
答案 0 :(得分:1)
而不是这样做 - &gt; return super.getView(position, convertView, parent);
您应该返回变量行,因为这是您自己构建的ui视图。 getView()方法中的return row;