我試圖擴展BaseAdapter
以使自定義listview
。但它說:Android BaseAdapter中預期的方法調用
getCount()方法中預期的方法調用。
我知道這是一個數組,所以如何獲取它?我基本上是這個領域的一個nube。這裏是我的代碼,我曾嘗試申請:
public class customAdapter extends BaseAdapter implements View.OnClickListener {
private Context context;
private String[] restaurant;
private String[] address;
private String[] time;
private static LayoutInflater layoutInflater = null;
public Resources res;
int image[];
ListModel tempvalues = null;
int i=0;
public customAdapter(MainActivity mainActivity, String[] rest, String[] add,String[] tim,int[] img){
restaurant = rest;
context=mainActivity;
address= add;
time = tim;
image = img;
layoutInflater = (LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return restaurant.length(); // Method call expected.
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
public class Holder{
TextView resname;
TextView resadd;
TextView restim;
ImageView imageView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Holder holder = new Holder();
View rowview;
rowview = layoutInflater.inflate(R.layout.custom_list_view_for_restaurant_names,null);
holder.resname = (TextView)rowview.findViewById(R.id.resnameTextView);
holder.resadd = (TextView)rowview.findViewById(R.id.address_textview);
holder.restim = (TextView)rowview.findViewById(R.id.time_textview);
holder.imageView = (ImageView)rowview.findViewById(R.id.imageView);
holder.resname.setText(restaurant[position]);
holder.resadd.setText(address[position]);
holder.restim.setText(time[position]);
holder.imageView.setImageResource(image[position]);
rowview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
return rowview;
}
@Override
public void onClick(View v) {
}
}
你會得到什麼錯誤? –
錯誤找不到符號方法length() - 這是錯誤 –
讓我知道如果您有任何問題 –