2017-01-04 2 views
1

EDIT2: У меня теперь есть правильный дизайн для моего макета, и я могу прокручивать, но у меня есть новая проблема с моим пользовательским адаптером. Когда я прокручиваю, мой editText теряют свой контент и заменяются другим содержимым из другого элемента. Но когда я использую SimpleCursorAdapter, у меня нет никаких проблем (но я не могу использовать свою кнопку).Android ListView не может прокручивать больше, плохой пользовательский адаптер?

Вот мой заказ адаптер:

private class MySimpleCursorAdapter extends SimpleCursorAdapter 
    { 
     ViewHolder vh; 
     public MySimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { 
      super(context, layout, c, from, to, flags); 
      cursor = c; 
     } 

     public View newView(Context _context, Cursor _cursor, ViewGroup parent) { 
      LayoutInflater inflater = (LayoutInflater) _context.getSystemService(_context.LAYOUT_INFLATER_SERVICE); 
      View view = inflater.inflate(R.layout.card_stock, parent, false); 
      vh = new ViewHolder(); 
      vh.idList = (TextView) view.findViewById(R.id.idList); 
      vh.themeList = (TextView) view.findViewById(R.id.themeList); 
      vh.questionList = (TextView) view.findViewById(R.id.questionList); 
      vh.reponseList = (TextView) view.findViewById(R.id.reponseList); 
      vh.difficulteList = (TextView) view.findViewById(R.id.difficultList); 
      vh.Supprimer = (Button) view.findViewById(R.id.buttonDelete); 
      vh.Modifier = (Button) view.findViewById(R.id.buttonModifier); 


      view.setTag(vh); 
      return view; 
     } 

     public void bindView(View view, Context Context, Cursor cursor) { 
       vh.idList.setText(cursor.getString(cursor.getColumnIndex(stock._ID))); 
       vh.themeList.setText(cursor.getString(cursor.getColumnIndex(stock.THEME))); 
       vh.questionList.setText(cursor.getString(cursor.getColumnIndex(stock.QUESTION))); 
       vh.reponseList.setText(cursor.getString(cursor.getColumnIndex(stock.REPONSE))); 
       vh.difficulteList.setText(cursor.getString(cursor.getColumnIndex(stock.DIFFICULTE))); 



      vh.Supprimer.setOnClickListener(new View.OnClickListener() 
      { 
       public void onClick(View v) { 
        View parentView = (View)v.getParent(); 
        TextView idList = (TextView) parentView.findViewById(R.id.idList); 

        int id = Integer.parseInt(idList.getText().toString()); 
        deleteOneCard(id); 
        Toast.makeText(container.getContext(), "Suppression de "+id, Toast.LENGTH_SHORT).show(); 
       } 
      }); 

      vh.Modifier.setOnClickListener(new View.OnClickListener() 
      { 
       public void onClick(View v) { 
        View parentView = (View)v.getParent(); 
        TextView idList = (TextView) parentView.findViewById(R.id.idList); 
        TextView themeList = (TextView) parentView.findViewById(R.id.themeList); 
        themeList.setFocusable(true); 
        themeList.requestFocus(); 
        /*TextView questionList = (TextView) parentView.findViewById(R.id.questionList); 
        TextView reponseList = (TextView) parentView.findViewById(R.id.reponseList); 
        TextView difficulteList = (TextView) parentView.findViewById(R.id.difficultList);*/ 

        int id = Integer.parseInt(idList.getText().toString()); 
        Toast.makeText(container.getContext(), "bouton Modifier pour "+id, Toast.LENGTH_SHORT).show(); 
       } 
      }); 

     } 
    } 



    public class ViewHolder 
    { 
     Button Supprimer, Modifier; 
     TextView idList, themeList, questionList, reponseList, difficulteList; 

    } 

Спасибо вам, ребята.

+0

Почему вы используете FrameLayout, а затем ListView ??? –

+0

используйте другой родительский макет над списком – Anjali

+0

Я попытался добавить родительский макет, изменил свой FrameLayout, но он не работает –

ответ

1

Установить ListView высота до match_parent. Таким образом, он будет занимать полную площадь родителя View.

<ListView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/listView" 
    android:scrollingCache="true"/> 
+0

Я попробовал это, посмотрю на картинку в конце моего сообщения. Но он делает что-то странное. –

1

Попробуйте добавить все прокручиваемое внутри одного RelativeLayout и этого внутри ScrollView.

<ScrollView> 
    <RelativeLayout> 
     // other elements 

или

<ScrollView> 
    <ListView> 

RelativeLayout в первом примере, является необходимым, поскольку элемент Scrollview принимает только одного ребенка.

+0

У меня уже есть relativeLayout внутри моего макета ListView, но я все еще пробовал с ScrollView и с (и без) другим относительным макетом и ничего не менял –

+0

Попробуйте использовать ScrollView, чтобы обернуть ListView. Обычно я это делаю. – TheMechanic

+0

Когда я это делаю, у меня есть тот же результат, что и мой последний снимок, с моим editView, который стал прослушиваться –

1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/darker_gray"> 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollingCache="true"/> 

</RelativeLayout> 

или

Использование LinearLayout и изменить ListView высоту 0dp и добавить weight=1

<LinearLayout 
........ 
       android:orientation="vertical"> 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:scrollingCache="true"/> 

</LinearLayout> 
+0

Он по-прежнему делает ту же проблему, что и моя последняя фотография, я думаю, что моя проблема исходит из моего пользовательского адаптера курсора внутри моего класса Fragment –

0

У меня есть решающий моя проблема! В моем внутреннем классе, который расширяет SimpleCursorAdapter, в моей функции bindView мне пришлось снова инициализировать мой editText !! Например:

public void bindView(View view, Context Context, Cursor cursor) { 
      //EDIT 
      vh.idList = (TextView) view.findViewById(R.id.idList); 
      vh.themeList = (TextView) view.findViewById(R.id.themeList); 
      vh.questionList = (TextView) view.findViewById(R.id.questionList); 
      vh.reponseList = (TextView) view.findViewById(R.id.reponseList); 
      vh.difficulteList = (TextView) view.findViewById(R.id.difficultList); 
      vh.Supprimer = (Button) view.findViewById(R.id.buttonDelete); 
      vh.Modifier = (Button) view.findViewById(R.id.buttonModifier); 
      //END EDIT 

      vh.idList.setText(cursor.getString(cursor.getColumnIndex(stock._ID))); 
      vh.themeList.setText(cursor.getString(cursor.getColumnIndex(stock.THEME))); 
      vh.questionList.setText(cursor.getString(cursor.getColumnIndex(stock.QUESTION))); 
      vh.reponseList.setText(cursor.getString(cursor.getColumnIndex(stock.REPONSE))); 
      vh.difficulteList.setText(cursor.getString(cursor.getColumnIndex(stock.DIFFICULTE))); 



      vh.Supprimer.setOnClickListener(new View.OnClickListener() 
      { 
       public void onClick(View v) { 
        View parentView = (View)v.getParent(); 
        TextView idList = (TextView) parentView.findViewById(R.id.idList); 

        int id = Integer.parseInt(idList.getText().toString()); 
        deleteOneCard(id); 
        Toast.makeText(container.getContext(), "Suppression de "+id, Toast.LENGTH_SHORT).show(); 
       } 
      }); 

      vh.Modifier.setOnClickListener(new View.OnClickListener() 
      { 
       public void onClick(View v) { 
        View parentView = (View)v.getParent(); 
        TextView idList = (TextView) parentView.findViewById(R.id.idList); 
        TextView themeList = (TextView) parentView.findViewById(R.id.themeList); 
        themeList.setFocusable(true); 
        themeList.requestFocus(); 
        /*TextView questionList = (TextView) parentView.findViewById(R.id.questionList); 
        TextView reponseList = (TextView) parentView.findViewById(R.id.reponseList); 
        TextView difficulteList = (TextView) parentView.findViewById(R.id.difficultList);*/ 

        int id = Integer.parseInt(idList.getText().toString()); 
        Toast.makeText(container.getContext(), "bouton Modifier pour "+id, Toast.LENGTH_SHORT).show(); 
       } 
      }); 

     } 
Смежные вопросы