我有一个listview
包含项目 Apple,Banana,Orange ...在第二个屏幕中activity
,当我单击 Apple 上的特定项目时,它会导航到详细信息屏幕
这里的输出必须通过点击 --> Apple ..如果我滑动页面然后香蕉和下一次滑动橙色
苹果-->香蕉-->橙子
如果我点击香蕉——>那么它必须看起来像香蕉,然后向左滑动苹果..然后向右滑动......橙色。
因此,我在第二个屏幕中单击了哪个项目(香蕉)listview
,它必须出现在详细信息屏幕上,左滑上一个列表项目,右滑列表中的下一个项目。
香蕉-->左滑苹果->右滑橙色
如果我点击橙色 - >那么它必须看起来像橙色然后向左滑动香蕉..然后下一次向左滑动......橙色。香蕉
橙色-->左滑香蕉--->下一次左滑-->苹果
但是对于单击listview
...的每个项目的所有案例,我都会得到像 Apple--> Banana--> Orange 这样的输出。
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;
}
}
}
}