我有一个listview
包含项目Apple,Banana,Orange ......在第二个屏幕activity
当我点击Apple上的特定项目时,它会导航到详细信息屏幕
此处输出必须通过单击 - >来显示苹果..如果我刷页面然后香蕉和下一次刷橙色
苹果 - >香蕉 - >橙
如果我点击Banana - >然后它必须显示为香蕉然后离开苹果..并右键滑动...橙色。
我在第二个屏幕中点击(Banana)listview
的项目,它必须显示在详细信息屏幕上,左侧滑动上一个列表项目,右键滑动列表中的下一个项目。
Banana - >用于向左滑动Apple - >右滑动橙色
如果我点击橙色 - >然后它必须显示为橙色然后离开滑动香蕉..并为下一个左滑动...橙色。 香蕉
橙色 - >用于左侧滑动香蕉--->用于下一次左侧滑动 - > Apple
但是我得到像Apple这样的输出 - > Banana - > Orange,点击了listview
....
public class SecondScreen extends Activity {
ListView listView;
LayoutInflater lay;
MyApplication app;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.second);
app = ((MyApplication) getApplicationContext());
listView = (ListView) findViewById(R.id.yearlistss);
listView.setAdapter(new MyAdapter(SecondScreen.this,app.totalvalue));
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, final int arg2,
long arg3) {
Intent detailIntent =new Intent(SecondScreen.this, Details.class);
startActivity(detailIntent);
}
});
}
public class MyAdapter extends BaseAdapter {
Context context = null;
private ArrayList<String> temperList1;
public MyAdapter(SecondScreen secondScreen, ArrayList<String> totalvalue) {
this.temperList1 = totalvalue;
}
public int getCount() {
// TODO Auto-generated method stub
return temperList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return temperList;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View layout = null;
TextView totalval = null;
if (convertView == null) {
lay = LayoutInflater.from(getApplicationContext());
layout = lay.inflate(R.layout.secondlist, null);
totalval = (TextView) layout.findViewById(R.id.total);
} else {
layout = convertView;
}
totalval.setText("" + temperList1.get(position));
return layout;
}
}
}
public class MyApplication extends Application {
ArrayList<String> totalvalue = new ArrayList<String>();
}
public class Details extends FragmentActivity{
MyApplication app;
ViewPager pager;
MyFragmentPagerAdapter pagerAdapter;
public static int position ;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.detail);
app = ((MyApplication) getApplicationContext());
pager = (ViewPager) findViewById(R.id.pager);
FragmentManager fm = getSupportFragmentManager();
pagerAdapter = new MyFragmentPagerAdapter(fm,app.totalvalue);
pager.setAdapter(pagerAdapter);
}
public static class MyFragmentPagerAdapter extends FragmentPagerAdapter {
private final ArrayList<String> temperList;
public MyFragmentPagerAdapter(FragmentManager fm, ArrayList<String> totalvalue ) {
super(fm);
this.temperList = totalvalue;
}
public Fragment getItem(int position) {
return ThingFragment.newInstance((temperList.get(position)));
}
@Override
public int getCount(){
return temperList.size();
}
private static class ThingFragment extends Fragment {
private String name1;
static ThingFragment newInstance(String string ) {
ThingFragment f = new ThingFragment();
Bundle args = new Bundle();
args.putString("name",string );
f.setArguments(args);
return f;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
name1 = getArguments().getString("name");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.myfragment_layout, container, false);
TextView t = (TextView)v.findViewById(R.id.prodcutt);
t.setText(""+ name1);
return v;
}
}
}
}
答案 0 :(得分:0)
在OnItemClickListener
的水果列表中,您应该在Intent
中传递所选水果的位置,这样您就可以在详细信息活动中了解点击了哪些水果,如下所示:
Intent detailIntent =new Intent(SecondScreen.this, Details.class);
detailIntent.putExtra("fruitPosition", arg2);
startActivity(detailIntent);
然后在您的详细信息活动中,您将检索该号码并相应地定位ViewPager
:
setContentView(R.layout.detail);
app = ((MyApplication) getApplicationContext());
pager = (ViewPager) findViewById(R.id.pager);
FragmentManager fm = getSupportFragmentManager();
pagerAdapter = new MyFragmentPagerAdapter(fm,app.totalvalue);
pager.setAdapter(pagerAdapter);
Intent startIntent = getIntent();
int fruitPosition = startIntent.getIntExtra("fruitPosition", 0);
pager.setCurrentItem(fruitPosition);