首页新闻找找看学习计划

安卓一运行就崩溃,求助

0
[已解决问题] 解决于 2018-05-29 15:30
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);
这里为啥错误,求指点一下

LiuDanK的主页 LiuDanK | 初学一级 | 园豆:29
提问于:2018-05-27 19:16
< >
分享
最佳答案
0

重写适配器返回类型应该为View

LiuDanK | 初学一级 |园豆:29 | 2018-05-29 15:30
其他回答(1)
0

错误截图?

TCG2008 | 园豆:1145 (小虾三级) | 2018-05-28 11:02

已经找到了,原因在于我重写适配器的时候返回的是ListView类型的

支持(0) 反对(0) LiuDanK | 园豆:29 (初学一级) | 2018-05-29 15:30
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册