我想禁用触摸listView行时出现的橙色突出显示.到目前为止,在我的xml中我尝试了以下内容:
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
Run Code Online (Sandbox Code Playgroud)
更多信息:当用户触摸此listView对象的屏幕时,我希望零差异.
我是Android开发人员的新手,还在做很多事情.
我有一个主菜单显示使用以下代码,但无法解决如何禁用菜单中的选定项目.有人可以帮我提供一些示例代码吗?
public class listTest extends ListActivity {
@Override
public void onCreate(Bundle savedState) {
super.onCreate(savedState);
setListAdapter(ArrayAdapter.createFromResource(this, R.array.mainMenu,
android.R.layout.simple_list_item_1));
//not sure how to disable list items here
}
protected void onListItemClick(ListView list, View view, int position, long id) {
// can disable items when they are clicked on
view.setEnabled(false);
}
}
Run Code Online (Sandbox Code Playgroud)
string-array我的strings.xml文件中有一个:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="mainMenu">
<item>Item 1</item>
<item>Item 2</item>
<item>Item 3</item>
</string-array>
</resources>
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个列表视图,通过数据库中的记录填充.现在我必须让一些记录可见,但无法选择,我该如何实现呢?
这是我的代码
public class SomeClass extends ListActivity {
private static List<String> products;
private DataHelper dh;
public void onCreate(Bundle savedInstanceState) {
dh = new DataHelper(this);
products = dh.GetMyProducts(); /* Returns a List<String>*/
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.myproducts, products));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener( new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(), Toast.LENGTH_SHORT).show();
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
布局文件myproducts.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="16sp"> …Run Code Online (Sandbox Code Playgroud)