gpt4 book ai didi

java - 安卓 : marquee on listview don't work

转载 作者:行者123 更新时间:2023-12-01 14:19:09 25 4
gpt4 key购买 nike

我写了简单的ListView,但我有问题,当我从 ListView 中选择某些项目时,我想选取文本,但它不起作用我不知道为什么当我从listView.setOnItemSelectedListener复制代码时,我认为我正确地编写了代码(new OnItemSelectedListener() 到 listView.setOnItemClickListener(new OnItemClickListener() 当我单击时可以正常工作,但我只希望这用于选择。这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < 7; ++i) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("firstLine", menu[i]);
hm.put("secondLine", submenu[i]);
hm.put("icon", Integer.toString(ikons[i]));
aList.add(hm);
}
String[] from = { "icon", "firstLine", "secondLine" };
int[] to = { R.id.icon, R.id.firstLine, R.id.secondLine };
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList,
R.layout.alarm_row, from, to);
ListView listView = (ListView) findViewById(R.id.list);
listView.setAdapter(adapter);

listView.setOnItemSelectedListener(new OnItemSelectedListener() {

@Override
public void onItemSelected(AdapterView<?> arg0, View view,
int arg2, long arg3) {
TextView t = (TextView) view.findViewById(R.id.secondLine);
t.setSelected(true);
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub

}
});

listView.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View view, int arg2,
long arg3) {
// TODO Auto-generated method stub
/*
* TextView t = (TextView) view.findViewById(R.id.secondLine);
* t.setFocusable(true); t.setSelected(true);
*/
}
});
}

XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/panel1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:background="@drawable/listview_bg"
android:padding="6dip" >

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignBottom="@+id/secondLine"
android:layout_alignParentTop="true"
android:scaleType="center"
android:src="@drawable/alarm_icon" />

<TextView
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/icon"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Alarm" />

<TextView
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/icon"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Ustawienia Alarmu" />

</RelativeLayout>

我认为这应该可行,我不知道出了什么问题,我将非常感谢任何帮助。

最佳答案

尝试添加

t.requestFocus();

之后

t.setSelected(true);

onItemSelected

关于java - 安卓 : marquee on listview don't work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17790136/

25 4 0