抽屉式导航栏布局上的应用程序的所有活动

抽屉式导航栏布局上的应用程序的所有活动

本文介绍了抽屉式导航栏布局上的应用程序的所有活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动 - MainActivity用户登录页面,第二个活动在ListView中显示用户的详细信息(用户制作项目)。我想创建一个抽屉式导航栏的布局,会出现在活动。 但问题是,我的第二个活动延伸ListActivity在ListView控件来显示用户的详细资料,所以我不能延长别的。这里是我的第二个活动:

 公共类ProjectList扩展ListActivity {
ArrayList的<串GT;时listItems =新的ArrayList<串GT;();
ArrayAdapter<串GT;适配器;
ListView控件的ListView;
JSONArray项目= NULL;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.project_list_inflator);
    ListView控件=(ListView控件)findViewById(android.R.id.list);
    适配器=新ArrayAdapter<串GT;(这一点,android.R.layout.simple_list_item_1,listItems中);
    listView.setAdapter(适配器);
    新HttpGetHandler()执行();
}私有类HttpGetHandler扩展的AsyncTask<弦乐,太虚,太虚> {
    字符串jsonUrl =某些URL;
    字符串imgUrl的=htt​​p://canvasflip.com/protected/app/elements/userElements/;
    @覆盖
    保护无效doInBackground(字符串... PARAMS){
        HTTPGET HTTPGET =新HTTPGET(jsonUrl);
        // HTTPGET httpGet1 =新HTTPGET(imgUrl的);
        尝试{
            HTT presponse HTT presponse = MainActivity.httpClient.execute(HTTPGET);
            HttpEntity httpEntity = HTT presponse.getEntity();
            InputStream的内容= httpEntity.getContent();
            字符串结果= convertToString(内容);
            的JSONObject的JSONObject =新的JSONObject(结果);
            项目= jsonObject.getJSONArray(项目)。
            ProjectList.this.runOnUiThread(新的Runnable(){
                @覆盖
                公共无效的run(){
                    尝试{
                        的for(int i = 0; I< projects.length();我++){
                            的JSONObject p值= projects.getJSONObject(ⅰ);
                            字符串title = p.getString(标题);
                            listItems.add(职称);
                            adapter.notifyDataSetChanged();
                        }                    }赶上(例外五){
                        Log.d(MSG,e.toString());
                    }
                }
            });
        }赶上(例外五){
            的System.out.println(e.getMessage());
        }
        返回null;
    }    公共字符串convertToString(的InputStream的InputStream)抛出IOException
        的BufferedReader的BufferedReader =新的BufferedReader(新的InputStreamReader(InputStream的));
        串线=;
        字符串结果=;
        而((行= bufferedReader.readLine())!= NULL){
            结果+ =行;        }
        inputStream.close();
        返回结果;
    }
 }
}


解决方案

只是使具有抽屉式导航implementaion源新活动

公共类DrawerActivity扩展ListActivity
覆盖DrawerLayout为

in onCreate of your drawer Activity initialize the drawer layout as,

drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout1);

And let your MainActivity extends the DrawerAcivity.

then replace the setContentView as given.

//  setContentView(R.layout.activity_main);

    LayoutInflater inflater = (LayoutInflater) getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View contentView = inflater.inflate(R.layout.activity_main, null, false);
    drawerLayout.addView(contentView, 0);

I have done this for my whole application successfully.

happy coding :)

这篇关于抽屉式导航栏布局上的应用程序的所有活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 01:04