我正在做一个项目,目前需要一个列表,当列表中的特定项目被点击时,出现另一个列表活动。是否有任何解决方案,以便如何从一个listview活动转移到另一个。我目前使用http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/作为我的ListView的参考。在Android应用程序的ListView内的ListView
0
A
回答
0
一个解决办法是:
创建第二个ListView的活动并实施,通过使用常规的意图打开第二ListViewActivity一个OnItemClickListener第一ListActivity。
listView = (ListView) findViewById(R.id.mylistview);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
Intent intent = new Intent(FirstListActivity.this, SecondListActivity.class);
Bundle bundle = new Bundle();
bundle.putString("pos", position);
intent.putExtras(bundle);
startActivity(intent);
}
});
UPDATE:
我已经写了一个简单的例子列表应用程序。您可以使用它进行检查。包含可以打开第二个列表活动的代码,但注释掉了。如果你得到这个例子,你就会越来越近。然后你可以尝试注释掉Intent代码。
package com.adpog.listviewexample;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the ListView resource.
ListView mainListView = (ListView) findViewById(R.id.my_list);
// Set the Adapter as the ListView's adapter.
mainListView.setAdapter(new BaseAdapter(){
// Create and populate a List of planet names.
String[] planets = new String[] {"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune" };
@Override
public int getCount() {
return planets.length;
}
@Override
public Object getItem(int pos) {
return planets[pos-1];
}
@Override
public long getItemId(int pos) {
return 0;
}
@Override
public View getView(int pos, View view, ViewGroup viewgroup) {
if(view == null){
/**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
<TextView
android:id="@+id/item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text not set" />
</LinearLayout>
*/
view = View.inflate(getApplicationContext(), R.layout.row, null);
}
return view;
}
});
mainListView.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Log.d("ListView", "Pos: " + arg2 + ", long : "+arg3);
Toast.makeText(getApplicationContext(), "Test " + arg2, Toast.LENGTH_SHORT).show();
/* Alternative way; opens a new Activity
Intent intent = new Intent(this, SecondListViewActivity.class);
intent.putExtra("position", pos);
startActivity(intent);
*/
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
/**
* Implement an action for each item click.
*/
mainListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Log.d("ListView", "OnClickPos: " + arg2 + ", long : "+arg3);
Toast.makeText(getApplicationContext(), "Test " + arg2, Toast.LENGTH_SHORT).show();
}
});
}
}
0
api规定了ExpandableListView。您的要求看起来非常接近它
相关问题
- 1. Android:像RetailMeNot应用程序的ListView
- 2. xml中的Listview android应用程序
- 3. listView崩溃的应用程序android
- 4. 无法点击Android应用程序中的ListView内容
- 5. android聊天应用程序 - ListView vs ScrollView
- 6. ListView和ArrayAdapter配置,Android应用程序
- 7. Android ListView崩溃了应用程序
- 8. Android应用程序 - ListView不工作
- 9. ListView内的Android EditText?
- 10. Android内存泄漏与ListView中的ListView
- 11. ListView崩溃应用程序
- 12. ListView崩溃应用程序
- 13. 在基于android的应用程序的ListView中切割文本
- 14. 如何在Android的listview中显示应用程序图标?
- 15. Android:在基于listView的应用程序中处理onItemClick()
- 16. ListView在Android中崩溃的应用程序
- 17. 我如何在Android应用程序中看到完整的ListView
- 18. 在android listview中的应用程序闪烁问题
- 19. 如何在Android应用程序的listview中添加项目?
- 20. 如何在ListView android应用程序的中心设置文本?
- 21. 如何在Listview中显示xmpp的值android应用程序
- 22. 把页脚放在动态增长的ListView Android应用程序
- 23. 如何在Android应用程序中显示数据从ListView作为ListView
- 24. Windows Phone 8应用程序中的ListView
- 25. 的Android在ListView
- 26. ListView没有出现在应用程序
- 27. 在FXML应用程序中预填ListView
- 28. 在web应用程序中创建ListView
- 29. Android ListView响应
- 30. NullPointerException将Android的ArrayAdapter设置为YouTube应用程序中的ListView
恐怕需要澄清一些。您的标题意味着一个两级列表视图。如果这就是你需要的,请参阅http://developer.android.com/reference/android/widget/ExpandableListView.html。否则,如果您需要在项目单击时打开另一个活动,只需使用Intent和context.startActivity()即可。 –
使用2个列表片段,并在同一个活动中切换它们。 –