ListView中的TextField可聚焦性

时间:2012-10-22 13:49:33

标签: android xml

我是Android的新手以及想要制作自定义适配器的内容,以便每行都能保存图像并在其旁边显示一些信息。我还想放置一个textField。我这样做了但是我可以&# 39;使用它们,意味着它们应该是它们应该出现但是当我触摸它时它从不打开软键盘。我猜是它没有得到请求的焦点。任何想法?我将发布xml我写的很多,一定是一个我不知道的领域。非常感谢你的时间。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip"
    android:descendantFocusability="blocksDescendants" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_marginRight="6dip"
    android:src="@drawable/std" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/padding_small"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Name" />



    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="45dp"
        android:text="TextView"
        android:textSize="10dp" />

</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/padding_small"
    android:orientation="horizontal" >



    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Grade" />





<EditText
    android:id="@+id/txtPassword"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPassword" >

</EditText>

</LinearLayout>


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/padding_small"
    android:orientation="horizontal" >



    <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Comment" />










    <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="25dp"
        android:textSize="10dp" />

</LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/padding_small"
            android:orientation="horizontal" >



    <TextView
        android:id="@+id/textView7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Present" />


    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp" />

</LinearLayout>

那是我的getView方法

    public View getView(final int position, View convertView, ViewGroup parent) {


    convertView=null;


    ViewHolder holder;

    if (convertView == null) {

        convertView = mInflater.inflate(com.example.myapp.R.layout.rw, null);           

        TextView tt = (TextView) convertView.findViewById(mIds[1]);
        TextView bt = (TextView) convertView.findViewById(mIds[0]);
        TextView btt = (TextView) convertView.findViewById(mIds[2]);
        EditText bttt = (EditText) convertView.findViewById(mIds[3]);
        TextView a = (TextView) convertView.findViewById(mIds[4]);
        TextView av= (TextView) convertView.findViewById(mIds[5]);
        TextView avt= (TextView) convertView.findViewById(mIds[6]);
        CheckBox check = (CheckBox) convertView.findViewById(mIds[7]);


        if (tt != null) {
              tt.setText(mContent.get(position));
              tt.setTextColor(Color.RED);
       }
        if(bt != null){
              bt.setText("Name: ");
              bt.setTextColor(Color.BLUE);
        }
        if(btt != null){
              btt.setText("Grade:");
              btt.setTextColor(Color.BLUE);
        }
        if(a != null){
          a.setText("Comments:"); 
          a.setTextColor(Color.BLUE);
      }
      if(av != null){
          av.setText("..."); 
          av.setTextColor(Color.RED);
      }
      if(avt != null){
          avt.setText("Present:"); 
          avt.setTextColor(Color.BLUE);
      }

      holder = new ViewHolder(tt);

          ((CheckBox)convertView.findViewById(mIds[7])).setOnCheckedChangeListener(new
              onCheckedChangeListener() { 

            public void onCheckedChanged(CompoundButton buttonView, 
                                                    boolean isChecked) { 
              // TODO Auto-generated method stub 
              if (buttonView.isChecked()) { 
                  checkModel.get(position).status=true;
              } 

            }
           });


    }else {

    holder = (ViewHolder) convertView.getTag();

     }   



       ((CheckBox)convertView.findViewById(mIds[7])).setChecked(checkModel.get(position).status);
     ((EditText) convertView.findViewById(mIds[3])).setText("lalla");

         return convertView;
     }

2 个答案:

答案 0 :(得分:1)

要在textview旁边保留图片,请在onCreate()中的代码中执行以下操作:

          phoneno.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(android.R.drawable.sym_action_call), null);

答案 1 :(得分:1)

我认为,Android正在点击ListView而不是TextView。尝试为EditText

以外的组件调整这些设置
android:focusable="false"
android:focusableInTouchMode="false"

或尝试

android:focusable="true"
android:focusableInTouchMode="true"

代表EditText

为什么你有这么多的LinearLayouts,尝试用RelativeLayout

替换它
相关问题