错误在活动设置ExpandableListView [英] Error in setting ExpandableListView in activity

查看:141
本文介绍了错误在活动设置ExpandableListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    public class Official_Activity extends Activity{
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.official_data2);
    setupViewComponent();

    new setList().execute();
}

 private void setupViewComponent() {
    // TODO Auto-generated method stub
     ExpandableListView list = (ExpandableListView)findViewById(R.id.list);
}

private class setList extends AsyncTask <Void, Void, List<News>>{

    List<Map<String, Object>> groups;
    List<List<HashMap<String, Object>>> childs;




     final ProgressDialog progDlg3 = new ProgressDialog(Official_Group.group);


    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();
        progDlg3.setTitle("Please wait");
        progDlg3.setMessage("Loading...");
        progDlg3.setIcon(android.R.drawable.ic_dialog_info);
        progDlg3.setCancelable(false);
        progDlg3.show();
    }

    @Override
    protected List<News> doInBackground(Void... arg0) {
        // TODO Auto-generated method stub
        List<News> newes = null;
        try {
            newes = GetJson.update();
            return newes;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return newes;


    }

    protected void onPostExecute(List<News> result){

         groups = new ArrayList<Map<String, Object>>();
        Map<String, Object> group1 = new HashMap<String, Object>();
        group1.put("ItemTitle", "Earthquake report");
        group1.put("ItemText", "Data from USGS");
        Map<String, Object> group2 = new HashMap<String, Object>();
        group2.put("ItemTitle", "Weather info");
        group2.put("ItemText", "Show weather info");
    groups.add(group1);
    groups.add(group2);

    List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
    for(News news : result){
        HashMap<String, Object> item = new HashMap<String, Object>();
        item.put("ItemTitle", news.getPlace());
        item.put("ItemText", "Magnitude: "+news.getMag());
        item.put("latit", news.getLatit());
        item.put("longit", news.getLongit());
        item.put("date", news.getTime());
        item.put("tzone", news.getTzone());
        data.add(item);
    }

List<HashMap<String, Object>> weather = new ArrayList<HashMap<String, Object>>();
    HashMap<String, Object> item2 = new HashMap<String, Object>();
    item2.put("ItemTitle", "Coming Soon");
    item2.put("ItemText", "");
    item2.put("latit", "");
    item2.put("longit", "");
    item2.put("date", "");
    item2.put("tzone", "");
    weather.add(item2);

     childs = new ArrayList<List<HashMap<String, Object>>>();
    childs.add(data);
    childs.add(weather);

    ExpandableListAdapter mExpaListAdap = new SimpleExpandableListAdapter(
            this,
            groups,
            R.layout.list_item,
            new String[] {"ItemTitle", "ItemText"},                   
            new int[] {R.id.ItemTitle, R.id.ItemText},
            childs,                                     
            R.layout.list_earthquake,
            new String[] {"ItemTitle", "ItemText", "latit", "longit", "date", "tzone"},
            new int[] {R.id.ItemTitle, R.id.ItemText, R.id.latit, R.id.longit, R.id.date, R.id.tzone}
            );

        list.setAdapter(mExpaListAdap);
      progDlg3.dismiss();     
    }



 }
   }

但被发现的错误:

But error was found:

The constructor SimpleExpandableListAdapter(Official_Activity.setList,
List<Map<String,Object>>, int, String[], int[], List<List<HashMap<String,Object>>>,
int, String[], int[]) is undefined

怎样才可以解决呢?

How can it be solved?

code的getJSON的:有意向的ListView(JSON数据)

code of getJson: Intent with ListView (JSON data)

9/8更新:
之后,我已经改变这个为Official_Activity.this,又发现一个错误:

9/8 update: After I've change "this" to "Official_Activity.this", another error is found:

9月8日至八日:34:33.975:E / AndroidRuntime(335):了java.lang.RuntimeException:无法启动活动ComponentInfo {} com.android.abc/com.android.abc.Official_Activity:java.lang中。 NullPointerException异常

08-08 09:34:33.975: E/AndroidRuntime(335): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.abc/com.android.abc.Official_Activity}: java.lang.NullPointerException

有没有在code任何错误?

Is there any bugs in the code?

推荐答案

您是在内部类,所以这个 Official_Activity.setList ,这是不是一个背景,你必须写 Official_Activity.this 代替,如下所示:

You are in an innerclass, so "this" is Official_Activity.setList class, which is not a context, you have to write Official_Activity.this instead, like the following:

new SimpleExpandableListAdapter(
            Official_Activity.this,
            groups,
            R.layout.list_item,
            new String[] {"ItemTitle", "ItemText"},                   
            new int[] {R.id.ItemTitle, R.id.ItemText},
            childs,                                     
            R.layout.list_earthquake,
            new String[] {"ItemTitle", "ItemText", "latit", "longit", "date", "tzone"},
            new int[] {R.id.ItemTitle, R.id.ItemText, R.id.latit, R.id.longit, R.id.date, R.id.tzone}
            );

这篇关于错误在活动设置ExpandableListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆