0

3 つの rows( ) を持つビューにデータをロードし、LinearLayout各行には 3があり、フォーカスが行のTextView最後と にある場合は同じビューを更新しています。TextViewKeyEvent.KEYCODE_DPAD_RIGHT

ビューを更新できますKeyEvent.KEYCODE_DPAD_RIGHTが、更新されたビューの同じ行にフォーカスが戻りません。

質問:ビューが更新されたときに、更新されたビューの同じ行にフォーカスを維持したいのですが、

. . .

  <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/linearlayout03" >

            <LinearLayout
                android:id="@+id/linearLayout1"
                android:layout_width="fill_parent"
                android:layout_height="74dp"
                android:background="@drawable/background" >
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout2"
                android:layout_width="fill_parent"
                android:layout_height="74dp"
                android:background="@drawable/background" >
            </LinearLayout>

            <LinearLayout
                android:id="@+id/linearLayout3"
                android:layout_width="fill_parent"
                android:layout_height="74dp"
                android:background="@drawable/background" >
            </LinearLayout>
 </LinearLayout>

. . .

線形レイアウトの行を埋める

 public void listfill(final LinearLayout ll, CustTextView[] tv, final List<Eventinfo> name, final int curf) {
        final List<Eventinfo> nameref = name;
            ll.removeAllViews();
            if (name.size() == 0) {
                name.add(new Eventinfo(true));
                name.add(new Eventinfo(true));
                name.add(new Eventinfo(true));
            }
            tv = new CustTextView[name.size()];
            for (int i = 0; i < name.size(); i++) {
                final Eventinfo evinfo = name.get(i);
                Utils.println("ev info: "+evinfo);

                tv[i] = new CustTextView(getApplicationContext());
                LinearLayout.LayoutParams params2;
                if (i != (name.size()-1)){
                    int x = 0;
                    if (i == 0){
                        tv[i].setViewLeft(true);
                        if (!name.get(0).isEmpty)
                            x = (int) calwidth(name.get(0).getEtime());
                        else 
                            x = (int) calwidth(name.get(0).getDur() + 0);
                    }else
                        x = (int) calwidth(name.get(i).getDur() + 0);

                        params2 = new LinearLayout.LayoutParams(
                                (int) x, 74);
                }
                else{
                    tv[i].setViewRight(true);
                    params2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 74);
                }
                tv[i].setLayoutParams(params2); 
                tv[i].setText(name.get(i).getName());
                tv[i].setTextColor(Color.WHITE);
                System.out.println(" .... " + name.get(i).getName() + i);
                final int z = i;

                tv[i].setOnFocusChangeListener(new methodOnFocusinlistfill(i, curf, nameref.get(i), tv[i].getisViewRight(), tv[i].getisViewLeft()));

                tv[i].setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if(z == 0){
                            String url = proxy.getUrl(gevinfo.getCid());
                            // call the tune channel API..
                            mediaPlayer.tune(url);
                        }
                    }
                });
                ll.addView(tv[i]);
            }
}

上記のメソッドは、以下に示すキーイベントのビューを埋める(更新)ために呼び出されます

  case KeyEvent.KEYCODE_DPAD_RIGHT:       
  if (( cur_focus == 8 || cur_focus == 9 || cur_focus == 10 ) && newRight //to check if it is the last textview){
                stTime.add(Calendar.HOUR,1);
                stTime.add(Calendar.MINUTE,30);
                enTime.add(Calendar.HOUR,1);
                enTime.add(Calendar.MINUTE,30);

                getStimeAndEtime();// will gives the start and end time 
                getEventinforclist();// based on start and end time it will get the data for the respective time duration and calls fill layout to update the view
            }

助けてください、事前に感謝します。

4

2 に答える 2

0

@sayed.jalil の助けに感謝します。上記のコードで行われた変更は、含まれている .xml ファイルにあります。

      android:descendantFocusability="afterDescendants"
      android:focusable="false"

3 つの LinearyLayout すべてで、フォーカスが TextViews である子ビューに移動し、現在のフォーカスに基づいてフォーカスを要求する新しいメソッド 'returnfocus()' が含まれています。

case KeyEvent.KEYCODE_DPAD_RIGHT:       
if (( cur_focus == 8 || cur_focus == 9 || cur_focus == 10 ) && newRight //to check if it is the     last textview){
            stTime.add(Calendar.HOUR,1);
            stTime.add(Calendar.MINUTE,30);
            enTime.add(Calendar.HOUR,1);
            enTime.add(Calendar.MINUTE,30);

            getStimeAndEtime();// will gives the start and end time 
            getEventinforclist();// based on start and end time it will get the data for the respective time duration and calls fill layout to update the view
            returnfocus();//new method added to retain the focus in same row
        }

returnfocus() メソッドは、

public void returnfocus(){
    System.out.println("current focus in returnfocus: "+cur_focus);

    if (copycur == 8){
        l1.requestFocus();
    }else if (copycur == 9){
        l2.requestFocus();
    }else if (copycur == 10){
        l3.requestFocus();
    }
}
于 2013-12-05T04:23:30.133 に答える