gpt4 book ai didi

android - 在android中滑动 ListView

转载 作者:行者123 更新时间:2023-11-29 15:25:07 24 4
gpt4 key购买 nike

如何向右滑动 1-2 ListView 2-3 向右 ListView 以及 1-2 左侧 2-3 左侧

enter image description here

我是 android 新手,我想向右滑动 1-2 ListView 、向右滑动 2-3 ListView 以及向左滑动 1-2、向左滑动 2-3,

我怎样才能做到这一点?

提前致谢。

这是我的代码

public void 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;

}

最佳答案

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

关于android - 在android中滑动 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14064743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com