package com.example.jiaoxh.myapplication1;
import android.content.Context;
import android.graphics.Color;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AmenitiesActivity extends AppCompatActivity {
ArrayList<Map<String,String>>items=new ArrayList<Map<String, String>>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_amenities);
//这里的错误貌似
Map<String, String> map = new HashMap<String, String>();
map.put("textView_name", "111");
map.put("textView_price", "222");
items.add(map);
ListView listView=(ListView)findViewById(R.id.listView_amenities);
MyAdapter myAdapter=new MyAdapter(this,items,R.layout.list_item,new String[]{"textView_name","textView_price"},new int[]{R.id.textView_name,R.id.textView_price});
listView.setAdapter(myAdapter);
}
//重写适配器
class MyAdapter extends SimpleAdapter {
public MyAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ListView listView=(ListView)findViewById(R.id.listView_amenities);
if(position%2!=0){
listView.setBackgroundColor(Color.GRAY);
}else{
listView.setBackgroundColor(Color.TRANSPARENT);
}
return listView;
}
}
}
不知道
Map<String, String> map = new HashMap<String, String>();
map.put("textView_name", "111");
map.put("textView_price", "222");
items.add(map);
这里为啥错误,求指点一下
重写适配器返回类型应该为View
错误截图?
已经找到了,原因在于我重写适配器的时候返回的是ListView类型的