在ListView文本字段可聚焦性 [英] TextField focusability in a ListView
问题描述
我是新来的Android,什么想创建一个自定义适配器使每一行将举行的形象和它旁边的一些information.I还想放置textField.I这样做,但我不能使用它们,这意味着他们出现,因为他们应该是,但是当我抚摸它,它永远不会打开softkeyboard.My的猜测是,它并没有得到所要求的focus.Any想法?我会后我写了XML那么多必须是现场,我是missing.Thank你这么多的时间。
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =机器人:ATTR /列表preferredItemHeight
机器人:填充=6DIP
机器人:descendantFocusability =blocksDescendants>< ImageView的
机器人:ID =@ + ID /图标
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_marginRight =6DIP
机器人:SRC =@绘制/ STD/> <的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =@扪/ padding_small
机器人:方向=横向> <的TextView
机器人:ID =@ + ID / textView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=名称/> <的TextView
机器人:ID =@ + ID / textView2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =45dp
机器人:文字=TextView的
机器人:TEXTSIZE =10dp/>< / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =@扪/ padding_small
机器人:方向=横向> <的TextView
机器人:ID =@ + ID / textView3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=级/><的EditText
机器人:ID =@ + ID / txtPassword
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
安卓的inputType =textPassword>< /&的EditText GT;< / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =@扪/ padding_small
机器人:方向=横向> <的TextView
机器人:ID =@ + ID / textView5
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=注释/>
<的TextView
机器人:ID =@ + ID / textView6
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =25dp
机器人:TEXTSIZE =10dp/>< / LinearLayout中>
<的LinearLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =@扪/ padding_small
机器人:方向=横向> <的TextView
机器人:ID =@ + ID / textView7
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=present/>
<复选框
机器人:ID =@ + ID / checkBox1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginLeft =20dp/>< / LinearLayout中>
这是我的getView方法
公共查看getView(最终诠释的立场,观点convertView,父母的ViewGroup){
convertView = NULL;
ViewHolder持有人; 如果(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(MID的[5]);
TextView的AVT =(TextView中)convertView.findViewById(MIDS [6]);
复选框检查=(复选框)convertView.findViewById(MIDS [7]);
如果(TT!= NULL){
tt.setText(mContent.get(位置));
tt.setTextColor(Color.RED);
}
如果(BT!= NULL){
bt.setText(姓名:);
bt.setTextColor(Color.BLUE);
}
如果(BTT!= NULL){
btt.setText(等级);
btt.setTextColor(Color.BLUE);
}
如果(一个!= NULL){
a.setText(评论:);
a.setTextColor(Color.BLUE);
}
如果(AV!= NULL){
av.setText(...);
av.setTextColor(Color.RED);
}
如果(AVT!= NULL){
avt.setText(present:);
avt.setTextColor(Color.BLUE);
} 支架=新ViewHolder(TT); ((复选框)convertView.findViewById(MIDS [7]))。setOnCheckedChangeListener(新
onCheckedChangeListener(){ 公共无效onCheckedChanged(CompoundButton buttonView,
布尔器isChecked){
// TODO自动生成方法存根
如果(buttonView.isChecked()){
checkModel.get(位置).STATUS = TRUE;
} }
});
}其他{ 支架=(ViewHolder)convertView.getTag(); } ((复选框)convertView.findViewById(MIDS [7]))setChecked(checkModel.get(位置).STATUS);
((EditText上)convertView.findViewById(MIDS [3]))的setText(拉拉); 返回convertView;
}
我认为,Android是服用该点击上的的ListView
,而不是你的<$ C点击$ C>的TextView 。尝试超过的EditText
机器人:可聚焦=假
机器人:focusableInTouchMode =假
或尝试
机器人:可聚焦=真
机器人:focusableInTouchMode =真
你的的EditText
。
和你为什么有这么多的LinearLayouts,请尝试使用 RelativeLayout的<替换它/ A>
I 'm new to android and what want to make a custom Adapter so that each row would hold an image and next to it some information.I want also to place a textField.I did so but i can't use them,meaning they appear as they should be but when i touch it it never open the softkeyboard.My guess is that it doesn't get the requested focus.Any ideas?I'll post the xml i've written so much must be a field that i'm missing.Thank you so much for your time.
<?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>
and that's my getView method
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;
}
I think, android is taking the click as the click on the ListView
rather than your TextView
. Try tweaking these settings for your components other than EditText
android:focusable="false"
android:focusableInTouchMode="false"
or try
android:focusable="true"
android:focusableInTouchMode="true"
for your EditText
.
And why do you have so many LinearLayouts, try replacing it with a RelativeLayout
这篇关于在ListView文本字段可聚焦性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!