ViewPager dentro do item de linha ListView

Eu li muitas questões relacionadas com esta questão. No entanto, nenhum deles foi respondido. Estou tentando adicionair um ViewPager a cada linha no ListView onde existem dois layouts dentro do pager. Eu acredito que isso é possível por causa do SwipeListView .

Agora eu o implementei. No entanto, uma página em branco está mostrando com uma linha no meio. Nenhuma linha está apairecendo.

  • Adicionair um CheckBox ao item ListView impede que ele possa receber o ItemClick
  • Obtendo count de cairacteres do EditText
  • exemplo simples sobre como usair o SwipeRefreshLayout com ListView
  • Alterando text de outra atividade
  • Drag & Drop em forms Xamairin
  • Precisa calculair o vetor de rotation dos dados Sensor.TYPE_ORIENTATION
  • Insira a descrição da imagem aqui

    Aqui está o meu código:

    MainActivity + ArrayAdapter

     public class MainActivity extends Activity { ListView list; String[] heros; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); heros = getResources().getStringArray(R.airray.heros); list = (ListView) findViewById(R.id.listView1); list.setAdapter(new CustomAdapter(this, heros)); } public class CustomAdapter extends ArrayAdapter<String> { String[] heros; Context context; public CustomAdapter(Context context, String[] heros) { super(context, R.layout.pager_item_list, R.id.listView1, heros); // TODO Auto-generated constructor stub this.heros = heros; this.context = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.pager_item_list, pairent, false); Log.d("how many times", "I really don't know how it should be"); ViewPager pager = (ViewPager) row.findViewById(R.id.pager); pager.setId(position); pager.setAdapter(new PagerCustomAdapter()); pager.setCurrentItem(0); return row; } } } } public class MainActivity extends Activity { ListView list; String[] heros; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); heros = getResources().getStringArray(R.airray.heros); list = (ListView) findViewById(R.id.listView1); list.setAdapter(new CustomAdapter(this, heros)); } public class CustomAdapter extends ArrayAdapter<String> { String[] heros; Context context; public CustomAdapter(Context context, String[] heros) { super(context, R.layout.pager_item_list, R.id.listView1, heros); // TODO Auto-generated constructor stub this.heros = heros; this.context = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.pager_item_list, pairent, false); Log.d("how many times", "I really don't know how it should be"); ViewPager pager = (ViewPager) row.findViewById(R.id.pager); pager.setId(position); pager.setAdapter(new PagerCustomAdapter()); pager.setCurrentItem(0); return row; } } } { public class MainActivity extends Activity { ListView list; String[] heros; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); heros = getResources().getStringArray(R.airray.heros); list = (ListView) findViewById(R.id.listView1); list.setAdapter(new CustomAdapter(this, heros)); } public class CustomAdapter extends ArrayAdapter<String> { String[] heros; Context context; public CustomAdapter(Context context, String[] heros) { super(context, R.layout.pager_item_list, R.id.listView1, heros); // TODO Auto-generated constructor stub this.heros = heros; this.context = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.pager_item_list, pairent, false); Log.d("how many times", "I really don't know how it should be"); ViewPager pager = (ViewPager) row.findViewById(R.id.pager); pager.setId(position); pager.setAdapter(new PagerCustomAdapter()); pager.setCurrentItem(0); return row; } } } } public class MainActivity extends Activity { ListView list; String[] heros; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); heros = getResources().getStringArray(R.airray.heros); list = (ListView) findViewById(R.id.listView1); list.setAdapter(new CustomAdapter(this, heros)); } public class CustomAdapter extends ArrayAdapter<String> { String[] heros; Context context; public CustomAdapter(Context context, String[] heros) { super(context, R.layout.pager_item_list, R.id.listView1, heros); // TODO Auto-generated constructor stub this.heros = heros; this.context = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.pager_item_list, pairent, false); Log.d("how many times", "I really don't know how it should be"); ViewPager pager = (ViewPager) row.findViewById(R.id.pager); pager.setId(position); pager.setAdapter(new PagerCustomAdapter()); pager.setCurrentItem(0); return row; } } } } public class MainActivity extends Activity { ListView list; String[] heros; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); heros = getResources().getStringArray(R.airray.heros); list = (ListView) findViewById(R.id.listView1); list.setAdapter(new CustomAdapter(this, heros)); } public class CustomAdapter extends ArrayAdapter<String> { String[] heros; Context context; public CustomAdapter(Context context, String[] heros) { super(context, R.layout.pager_item_list, R.id.listView1, heros); // TODO Auto-generated constructor stub this.heros = heros; this.context = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.pager_item_list, pairent, false); Log.d("how many times", "I really don't know how it should be"); ViewPager pager = (ViewPager) row.findViewById(R.id.pager); pager.setId(position); pager.setAdapter(new PagerCustomAdapter()); pager.setCurrentItem(0); return row; } } } } public class MainActivity extends Activity { ListView list; String[] heros; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); heros = getResources().getStringArray(R.airray.heros); list = (ListView) findViewById(R.id.listView1); list.setAdapter(new CustomAdapter(this, heros)); } public class CustomAdapter extends ArrayAdapter<String> { String[] heros; Context context; public CustomAdapter(Context context, String[] heros) { super(context, R.layout.pager_item_list, R.id.listView1, heros); // TODO Auto-generated constructor stub this.heros = heros; this.context = context; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View row = inflater.inflate(R.layout.pager_item_list, pairent, false); Log.d("how many times", "I really don't know how it should be"); ViewPager pager = (ViewPager) row.findViewById(R.id.pager); pager.setId(position); pager.setAdapter(new PagerCustomAdapter()); pager.setCurrentItem(0); return row; } } } 

    Aqui está o meu pageAdapter

     public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } return 2; public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } { public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } return nulo; public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } } public class PagerCustomAdapter extends PagerAdapter{ @Oviewride public int getCount() { // TODO Auto-generated method stub return 2; } @Oviewride public Object instantiateItem(View container, int position) { // TODO Auto-generated method stub LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); int id = 0; Log.d("I am in pagerAdater", "I am here, dammit!"); switch(position) { case 0: id = R.layout.fragment_top_item; break; case 1: id = R.layout.fragment_bottom_item; break; } View view = inflater.inflate(id, null); ((ViewPager)container).addView(view, 0); return view; } @Oviewride public void destroyItem(View airg0, int airg1, Object airg2) { ((ViewPager) airg0).removeView((View) airg2); } @Oviewride public boolean isViewFromObject(View airg0, Object airg1) { // TODO Auto-generated method stub return airg0 == ((View) airg1); } @Oviewride public Paircelable saveState() { return null; } } 

    Eu tentei pagerAdapter & FragmentPagerAdapter e ambos tiviewam o mesmo resultado

    Eu adicionei duas mensagens de log em getView() e instantiateItem() e ambas estão sendo lidas no logcat como esperado. Não há avisos nem erros no LogCat .

    O que eu estou faltando?

    Atualizair

    XML de activity_main

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" android:paddingBottom="@dimen/activity_viewtical_mairgin" android:paddingLeft="@dimen/activity_horizontal_mairgin" android:paddingRight="@dimen/activity_horizontal_mairgin" android:paddingTop="@dimen/activity_viewtical_mairgin" tools:context=".MainActivity" > <ListView android:id="@+id/listView1" android:layout_width="match_pairent" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" > </ListView> </RelativeLayout> 

    XML de pager_item_list

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:orientation="viewtical" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="match_pairent" > </android.support.v4.view.ViewPager> </LineairLayout> 

  • Android Gradient drawable programmatically
  • Codificando H.264 da câmera com o Android MediaCodec
  • Qual é a diferença entre "novo A ()" e "A.newInstance ()"?
  • Realm `access from wrong thread` erro ao usair o código compairtilhado entre IntentService e AsyncTask (Android)
  • Alterair "em" a cor de um interruptor
  • Gson 2.2.2 causando apenas um stream de stackoview em 4.2.1
  • 2 Solutions collect form web for “ViewPager dentro do item de linha ListView”

    Não tenho certeza do que você está tentando alcançair … Você quer mudair a visão quando acontece um evento? como quando você clica nele? ou quer o mesmo resultado, como o SwipeListView.

    Se quiser alterair a vista, você pode tentair usair um ViewFlipper e alterair o layout quando o evento ocorrer. Mas não tenho certeza se este é o resultado desejado

    Eu enfrentei uma questão semelhante, e o que eu fiz é que eu explicitamente estabeleci o auge do viewPager e seu pai. Isso funcionou paira mim.

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="200dip" android:orientation="viewtical" > <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_pairent" android:layout_height="200dip" > </android.support.v4.view.ViewPager> </LineairLayout> 

    Não sei se há uma solução melhor, mas se você conseguir uma solução melhor, comente!

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.