1

如何向右滑动 1-2 列表视图 2-3 列表视图右侧以及 1-2 左侧 2-3 左侧

在此处输入图像描述

我是 android 新手,我想向右滑动 1-2 列表视图 2-3 列表视图右侧以及 1-2 左侧 2-3 左侧,

我怎样才能做到这一点?

提前致谢。

这是我的代码

公共无效 onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.inspire);

    Context contex;

    activity = this;

    rowItems = fetchTwitterPublicTimeline();
    rowItems1 = fetchTwitterPublicTimeline1();
    rowItems2 = fetchTwitterPublicTimeline2();

    btn1 = (Button) findViewById(R.id.button1);
    btn2 = (Button) findViewById(R.id.button2);
    btn3 = (Button) findViewById(R.id.button3);

    TextView txtDesc = (TextView) findViewById(R.id.desc);
    TextView txtTitle = (TextView) findViewById(R.id.title);
    ImageView imageView = (ImageView) findViewById(R.id.icon);

    final ListView listView = (ListView) findViewById(R.id.listview);
    adapter = new InspireAdapter(this, R.layout.row, rowItems);
    listView.setAdapter(adapter);

    OnItemClickListener listener = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                final int position, long id) {

        }
    };

    listView.setOnItemClickListener(listener);

    final ListView listView1 = (ListView) findViewById(R.id.listview1);
    adapter1 = new InspireAdapter1(this, R.layout.row1, rowItems1);

    // listView1.setAdapter(adapter1);

    OnItemClickListener listener1 = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

        }
    };
    listView1.setOnItemClickListener(listener1);

    final ListView listView2 = (ListView) findViewById(R.id.listview2);
    adapter2 = new InspireAdapter2(this, R.layout.row2, rowItems2);

    // listView2.setAdapter(adapter2);

    OnItemClickListener listener2 = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

        }
    };
    listView2.setOnItemClickListener(listener2);

    btn1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            listView1.setVisibility(View.GONE);
            listView.setVisibility(View.VISIBLE);
            listView2.setVisibility(View.GONE);

            btn1.setTextColor(Color.BLACK);
            btn2.setTextColor(Color.WHITE);
            btn3.setTextColor(Color.WHITE);

        }
    });

    btn2.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            listView.setVisibility(View.GONE);
            listView1.setVisibility(View.VISIBLE);
            listView2.setVisibility(View.GONE);

            listView1.setAdapter(adapter1);

            btn2.setTextColor(Color.BLACK);
            btn1.setTextColor(Color.WHITE);
            btn3.setTextColor(Color.WHITE);
        }
    });

    btn3.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            listView2.setVisibility(View.VISIBLE);
            listView1.setVisibility(View.GONE);
            listView.setVisibility(View.GONE);

            listView2.setAdapter(adapter2);

            btn3.setTextColor(Color.BLACK);
            btn1.setTextColor(Color.WHITE);
            btn2.setTextColor(Color.WHITE);

        }
    });
}

public ArrayList<rowitem> fetchTwitterPublicTimeline() {
    ArrayList<rowitem> listItems = new ArrayList<rowitem>();

    try {
        URL twitter = new URL(
                "http://jaihoon.com/app-admin/API/getInspire.php?appKey=86fb269d190d2c85f6e0468ceca42a20&type=poem");
        URLConnection tc = twitter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));

        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            sb.append(line + "\n");
        }
        line = sb.toString();
        JSONObject ja = new JSONObject(line);
        JSONArray ja1 = ja.getJSONArray("AllInspires");

        for (int i = 0; i < ja1.length(); i++) {
            JSONObject jo = (JSONObject) ja1.get(i);
            rowitem r = new rowitem();

            String inspiresum = null;
            String inspititle = null;
            String inspiimage = null;
            String inspitype = null;
            String inspitext = null;

            // inspitype = ja1.getJSONObject(i).getString("inspiretype");
            // r.setInspiretype(inspitype);

            inspiresum = ja1.getJSONObject(i).getString("inspiresummary");
            r.setInspiresummary(inspiresum);

            inspititle = ja1.getJSONObject(i).getString("inspiretitle");
            r.setInspiretitle(inspititle);

            inspiimage = ja1.getJSONObject(i).getString("inspireimage");
            r.setInspireimage(inspiimage);

            inspitext = ja1.getJSONObject(i).getString("inspiretext");
            r.setInspiretext(inspitext);

            listItems.add(r);

        }

    } catch (MalformedURLException e) {
        Log.e("dhrumil", "MalformedURLException" + e.getMessage());
    } catch (IOException e) { // TODO Auto-generated catch block
        Log.e("dhrumil", "IOException" + e.getMessage()); // e.printStackTrace();
    } catch (JSONException e) { // TODO Auto-generated catch block
        Log.e("dhrumil", "JSONException " + e.getMessage());
    }
    return listItems;

}

public ArrayList<rowitem> fetchTwitterPublicTimeline1() {
    ArrayList<rowitem> listItems = new ArrayList<rowitem>();

    try {
        URL twitter = new URL(
                "http://jaihoon.com/app-admin/API/getInspire.php?appKey=86fb269d190d2c85f6e0468ceca42a20&type=essay");
        URLConnection tc = twitter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));

        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            sb.append(line + "\n");
        }
        line = sb.toString();
        JSONObject ja = new JSONObject(line);
        JSONArray ja1 = ja.getJSONArray("AllInspires");

        for (int i = 0; i < ja1.length(); i++) {
            JSONObject jo = (JSONObject) ja1.get(i);
            rowitem r = new rowitem();
            String inspiresum = null;
            String inspititle = null;
            String inspiimage = null;

            inspiresum = ja1.getJSONObject(i).getString("inspiresummary");
            r.setInspiresummary(inspiresum);

            inspititle = ja1.getJSONObject(i).getString("inspiretitle");
            r.setInspiretitle(inspititle);

            inspiimage = ja1.getJSONObject(i).getString("inspireimage");
            r.setInspireimage(inspiimage);

            listItems.add(r);

        }

    } catch (MalformedURLException e) {
        Log.e("dhrumil", "MalformedURLException" + e.getMessage());
    } catch (IOException e) { // TODO Auto-generated catch block
        Log.e("dhrumil", "IOException" + e.getMessage()); // e.printStackTrace();
    } catch (JSONException e) { // TODO Auto-generated catch block
        Log.e("dhrumil", "JSONException " + e.getMessage());
    }
    return listItems;

}

public ArrayList<rowitem> fetchTwitterPublicTimeline2() {
    ArrayList<rowitem> listItems = new ArrayList<rowitem>();

    try {
        URL twitter = new URL(
                "http://jaihoon.com/app-admin/API/getInspire.php?appKey=86fb269d190d2c85f6e0468ceca42a20&type=tweet");
        URLConnection tc = twitter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream()));

        StringBuilder sb = new StringBuilder();
        String line;
        while ((line = in.readLine()) != null) {
            sb.append(line + "\n");
        }
        line = sb.toString();
        JSONObject ja = new JSONObject(line);
        JSONArray ja1 = ja.getJSONArray("AllInspires");

        for (int i = 0; i < ja1.length(); i++) {
            JSONObject jo = (JSONObject) ja1.get(i);
            rowitem r = new rowitem();
            String inspiresum = null;
            String inspititle = null;
            String inspiimage = null;

            inspiresum = ja1.getJSONObject(i).getString("inspiresummary");
            r.setInspiresummary(inspiresum);

            inspititle = ja1.getJSONObject(i).getString("inspiretitle");
            r.setInspiretitle(inspititle);

            inspiimage = ja1.getJSONObject(i).getString("inspireimage");
            r.setInspireimage(inspiimage);

            listItems.add(r);

        }

    } catch (MalformedURLException e) {
        Log.e("dhrumil", "MalformedURLException" + e.getMessage());
    } catch (IOException e) { // TODO Auto-generated catch block
        Log.e("dhrumil", "IOException" + e.getMessage()); // e.printStackTrace();
    } catch (JSONException e) { // TODO Auto-generated catch block
        Log.e("dhrumil", "JSONException " + e.getMessage());
    }
    return listItems;

}

}

4

2 回答 2

3

https://github.com/jfeinstein10/SlidingMenu,检查一下。演示项目也可以从 google play 下载。

于 2012-12-28T04:57:17.750 回答
2

它很容易。在 android 最新版本中,Android 提供了一种创建项目滑动屏幕的方法。了解我们如何创建滑动导航及其具有向后兼容性

在此处输入图像描述

于 2012-12-28T05:43:51.633 回答