我有3个ListViews在一个布局,但在3个不同的片段。我想,当我向下滚动时,首先加载第一个列表视图和其他两个列表视图滚动背景在同一时间1更改片段相同的位置 显示在第二和第三个片段我从数据库加载列表视图。 Pic of 1st fragment如何同时在不同的片段中滚动3个列表视图?
//first fragment code
public class Quran extends Fragment {
ListView quranlst;
Parcelable state;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_quran, container, false);
}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
quranlst = (ListView) getActivity().findViewById(R.id.quranlist);
DatabaseAccess db = DatabaseAccess.getInstance(getActivity().getApplicationContext());
Intent it = getActivity().getIntent();
int p = it.getIntExtra("paya", 0);
int i = it.getIntExtra("saya", 0);
if (i != 0) {
List<String> lstsa;
db.open();
lstsa = db.getsaya(i);
db.close();
MyCustomAdapter adapter = new MyCustomAdapter(lstsa, Quran.this.getActivity());
quranlst.setAdapter(adapter);
} else if (p != 0) {
List<String> lstpa;
db.open();
lstpa = db.getpaya(p);
db.close();
MyCustomAdapter adapter = new MyCustomAdapter(lstpa, Quran.this.getActivity());
//handle listview and assign adapter
quranlst.setAdapter(adapter);
}
}
}
pic of Second fragment 这是我的第二个片段的代码列表视图中使用此代码
public class englisht extends Fragment {
ListView el;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_englisht, container, false);}
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
el = (ListView) view.findViewById(R.id.englishlst);
DatabaseAccess db = DatabaseAccess.getInstance(getActivity().getApplicationContext());
Intent it = getActivity().getIntent();
int i = it.getIntExtra("saya", 0);
int p = it.getIntExtra("paya", 0);
if (i != 0) {
List<String> lstenglishsurah;
db.open();
lstenglishsurah = db.geteaya(i);
db.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.mytextview, lstenglishsurah);
el.setAdapter(adapter);
} else if (p != 0) {
List<String> lstenglishparah;
db.open();
lstenglishparah = db.paraheng(p);
db.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.mytextview, lstenglishparah);
el.setAdapter(adapter);
}
}
}
**that is my third fragment code**
public class urdut extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//Returning the layout file after inflating
//Change R.layout.tab1 in you classes
return inflater.inflate(R.layout.activity_urdut, container, false);}
ListView urdulst;
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
urdulst = (ListView) view.findViewById(R.id.urdulst);
DatabaseAccess db = DatabaseAccess.getInstance(getActivity().getApplicationContext());
Intent it = getActivity().getIntent();
//SurahAyat
int i = it.getIntExtra("saya", 0);
int p = it.getIntExtra("paya", 0);
if (i!=0) {
List<String> lsturdusurah;
db.open();
lsturdusurah = db.getuaya(i);
db.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.mytextview, lsturdusurah);
urdulst.setAdapter(adapter);
}
else if (p!=0) {
List<String> lsturduparah;
db.open();
lsturduparah = db.parahurdu(p);
db.close();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.mytextview, lsturduparah);
urdulst.setAdapter(adapter);
}
}
}
您能分享设计屏幕的屏幕截图,因此我们可能会提出一些更好的方法,或者它有助于理解问题。 –
如何显示应用程序的设计 –
我上传应用程序的屏幕截图plz检查它 –