2017-01-04 17 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

+0

私はこれを試して、私の記事の最後に画像を見てください。しかし、それは変わったことがあります –

1

ScrollView内で1つのRelativeLayout内のすべてのスクロール可能なアイテムを追加してみてください。 ScrollView要素が一つだけ子を受け入れるため、最初の例で

<ScrollView> 
    <RelativeLayout> 
     // other elements 

又は

<ScrollView> 
    <ListView> 

RelativeLayoutが必要です。

+0

私は既にlistViewレイアウトの中にrelativeLayoutを持っていますが、まだScrollViewを試してみましたが、別の相対レイアウトでは何も変更されません。 –

+0

ListViewをラップするためにScrollViewを試してみてください。それは通常私がそれをやる方法です。 – 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と0dpListView高さを変更し、私は私の問題をリゾルバ持っ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

それは私の最後の画像と同じ問題を抱えている、私の問題は自分のカスタムカーソルアダプターから私のフラグメントクラス内に来ると思う –

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(); 
       } 
      }); 

     } 
関連する問題