gpt4 book ai didi

android - ListView 中的 TextField 可聚焦性

转载 作者:数据小太阳 更新时间:2023-10-29 02:36:27 26 4
gpt4 key购买 nike

我是 android 的新手,想制作一个自定义适配器,以便每一行都包含一个图像,旁边还有一些信息。我还想放置一个 textField。我这样做了,但我不能使用它们,意思是它们按应有的样子出现,但是当我触摸它时,它永远不会打开软键盘。我的猜测是它没有获得请求的焦点。有什么想法吗?我会发布我写了这么多的 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;
}

最佳答案

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

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

关于android - ListView 中的 TextField 可聚焦性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13012856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com