我有一些"卡片",这是一个带有TextView的简单LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/card_label_txt"
android:layout_width="wrap_content"
android:text="label" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后我的主片段有一个垂直的LinearLayout ..在这个主片段中我将这个"卡片"添加到主布局:
# main fragment layout
View view = inflater.inflate(R.layout.main_activity, null);
LinearLayout ll = (LinearLayout) view
.findViewById(R.id.main_activity_ll);
# get card
View card = inflater.inflate(R.layout.card, null);
# add to fragment layout
ll.addView(card);
Run Code Online (Sandbox Code Playgroud)
这非常好用我的卡填充片段布局的整个宽度.实际上我在期待什么.
现在我为我的卡创建了一个单独的类:
Class Card extends LinearLayout{
public Card(Context context) {
super(context);
View view = LayoutInflater.from(getContext()).inflate(
R.layout.card, null);
this.addView(view);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,如果我将卡添加到主片段布局中:
# main fragment layout
View view = inflater.inflate(R.layout.main_activity, null);
LinearLayout ll = (LinearLayout) view
.findViewById(R.id.main_activity_ll); …Run Code Online (Sandbox Code Playgroud) android android-context android-layout android-linearlayout android-fragments
我必须ListView在每个项目上做一个包含的内容EditText.如果EditText获得焦点,我必须显示一个对话框 - 条件严格适用于EditText获得焦点而不是按下时,因为即使没有按下也可以选择它...
为了做到这一点,我使用焦点监听器,EditText但是onFocusChanged当用户按下时,只有一次调用三次调用EditText,这意味着对话框被调用两次...
这是调用的顺序:
我没有任何其他特殊的处理ListView或EditText..所以它应该是从系统以某种方式,也许是因为我使用ListView上的EditText也是一个焦点View..
有没有人有任何想法为什么会发生这种情况,我怎么能"修复"这个?
先感谢您.