Android 将ListView传递给另一个ListView
我在一个片段中有listview,它显示sqlite数据库中的项。当我单击一个项目时,它会打开一个菜单,允许打开、添加到另一个listview或删除。我希望能够将它添加到另一个listview中的另一个片段中。我尝试使用捆绑包将其添加到另一个listview,但没有成功。我计划创建另一个数据库表来存储添加的数据并将其显示在新的listview中。这样行吗?或者你们有其他建议吗?你们可以将数据从一个片段发送到另一个片段。执行此操作的最佳方法是通过父活动。大概是这样的:Android 将ListView传递给另一个ListView,android,sqlite,listview,Android,Sqlite,Listview,我在一个片段中有listview,它显示sqlite数据库中的项。当我单击一个项目时,它会打开一个菜单,允许打开、添加到另一个listview或删除。我希望能够将它添加到另一个listview中的另一个片段中。我尝试使用捆绑包将其添加到另一个listview,但没有成功。我计划创建另一个数据库表来存储添加的数据并将其显示在新的listview中。这样行吗?或者你们有其他建议吗?你们可以将数据从一个片段发送到另一个片段。执行此操作的最佳方法是通过父活动。大概是这样的: public class M
public class MyActivity extends FragmentActivity implements MyFragmentListener {
MyFragment1 frag1;
MyFragment2 frag2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(0);
FragmentManager fm = getSupportFragmentManager();
frag1 = (MyFragment1) fm.findFragmentByTag("frag1");
frag1.setListener(this);
frag2 = (MyFragment2) fm.findFragmentByTag("frag2");
}
// Call this function from frag1 when you want to send the data to frag2
public void addToFrag2(ListItem item) {
frag2.addToList(item);
}
}
// Define whatever methods the fragments want to use to pass data back and forth
public interface MyFragmentListener {
void addToFrag2(ListItem item);
}