Reputation: 126
Hi I've been trying to use a custom list activity with a custom list item layout and I'm in desperate need for assistance. My custom adapter class which I use as the list adapter may be wrong or right but whatever it is the method getView() is not being used and when I put logs in it it doesn't show, my adapter class is this :
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);
}
}
and here is my adapter's construction
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);
}
I will much appreciate your comments on the matter.
Upvotes: 0
Views: 91
Reputation: 3134
Instead of doing this -> return super.getView(position, convertView, parent);
you should probably return the variable row because that is the ui view you really built yourself. return row;
in your getView() method
Upvotes: 1