我将 aListView
与自定义适配器一起使用。在这个适配器中,我想使用 aHorizontalScrollView
来连续显示完整的信息。我的文字很长,所以我必须滚动。不幸的是,我setOnItemClickListener
无法识别点击它。如果我删除horizontalScrollView,它会起作用。在过去的几个小时里,我在这里读了很多关于这个话题的文章,但没有什么能帮我解决这个问题。那么即使我的 ListView 也可以水平滚动,是否可以接收事件?
public void show_alert() {
final Dialog dia = new Dialog(this);
dia.setContentView(R.layout.alert);
dia.setTitle(String.format(res.getString(R.string.msg_11)));
dia.setCancelable(true);
list_alert = (ListView) dia.findViewById(R.id.alert_list);
list_alert.setAdapter(new MainActivityArrayAdapter(this, GetProtokollFileNames()));
this.list_alert.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
Toast.makeText(MainActivity.this,
"Item in position " + pos + " clicked", Toast.LENGTH_LONG).show();
dia.dismiss();
}
});
dia.show();
}
MainActivityArrayAdapter(...) 类使用 rowlayout.xml。
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
import android.content.Context;
import android.content.pm.LabeledIntent;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivityArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private String[] Values;
public MainActivityArrayAdapter(Context context, String[] values) {
super(context, R.layout.rowlayout, values);
this.context = context;
Values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.rowlayout, parent, false);
return rowView;
}
}
行布局.xml
<HorizontalScrollView android:id="@+id/horizontalScrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:scrollbarAlwaysDrawVerticalTrack="false" android:scrollbarStyle="insideOverlay" android:scrollbars="none" > <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_menu_name" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/lbl_datum" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="22.03.2013" /> <TextView android:id="@+id/lbl_time" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="10:50:45" /> </LinearLayout> <Space android:layout_width="10dp" android:layout_height="match_parent" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/lbl_strasse" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Straße" /> <TextView android:id="@+id/lbl_plz" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="plz" /> <TextView android:id="@+id/lbl_ort" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ort" /> </LinearLayout> <Space android:layout_width="10dp" android:layout_height="match_parent" /> <LinearLayout android:layout_width="wrap_content" android:clickable="false" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/lbl_auftraggeber" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Auftraggeber" /> <TextView android:id="@+id/textView5" android:clickable="false" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout> <TextView android:id="@+id/lbl_bemerkung" android:clickable="false" android:layout_width="354dp" android:layout_height="wrap_content" android:paddingLeft="50dp" android:text="Bemerkung" /> </LinearLayout> </HorizontalScrollView>
警报.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:descendantFocusability="blocksDescendants" android:orientation="vertical" > <ListView android:id="@+id/alert_list" android:clickable="true" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout>