J'écris ListView simple, mais j'ai un problème, je veux marquer le texte lorsque je sélectionne un élément de ma listview, mais ça ne fonctionne pas, je ne sais pas pourquoi je pense que j'écris le code correctement quand je copie mon code de listView.setOnItemSelectedListener (nouveau OnItemSelectedListener() à listView.setOnItemClickListener (nouveau OnItemClickListener() qui est correctement lorsque je clique, mais je veux ce que pour sélectionnez C'est mon code.android: marquise sur listview ne fonctionne pas
@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>
Je pense que cela devrait fonctionner, je n'ai aucune idée de ce qui ne va pas, je serai très reconnaissant pour toute aide.
ne fonctionne toujours pas:/Je ne sais pas ce qui est faux, car tout semble bien pour moi ... – pkruk
Take un regard sur les réponses ici- http://stackoverflow.com/questions/1827751/is-there-a-way-to-make-ellipsize-marquee-always-scroll, en particulier le dernier, je pense que cela convient à votre liste vie w exigence – Slartibartfast
aucune réponse de ce sujet ne m'a pas aidé je suis encore au point mort:/je ne sais pas ce qui ne va pas: / – pkruk