I have a listview contain items Apple, Banana, Orange …in second screen activity
when I click on particular item on Apple it navigates to Details screen
here output has to appear like by clicking on –> Apple ..if I swipe page then banana and for next swipe Orange
Apple–>Banana–>Orange
If I click on Banana –>then it has to appear like Banana then left swipe Apple ..and for right swipe…Orange.
So which item I clicked on(Banana) listview in second screen it has to appear on details screen and for left swipe previous list item and for right swipe next item in the list.
Banana–>for left swipe Apple
–>for right swipe Orange
If I click on Orange –>then it has to appear like Orange then left swipe Banana ..and for next left swipe…Orange.
Banana
Orange–>for left swipe Banana—>for next left swipe–>Apple
but am getting output like Apple–>Banana–>Orange for all the cases of each item clicked on the 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;
}
}
}
}
In the
OnItemClickListenerfor your list of fruits you should pass the position of the selected fruit in theIntentso you can know in the details activity which fruit was clicked, something like this:Then in your details activity you would retrieve that number and position the
ViewPageraccordingly: