【发布时间】:2015-08-16 17:23:00
【问题描述】:
“listView”有问题。我到处搜索,但问题没有出现。让我解释一下:
我的“布局”中有经典的“列表视图”:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/roza"
android:tileMode="repeat">
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#80ffffff"
android:alpha="200">
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_todos" />
</LinearLayout>
我创建自定义 list_row xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/list_name"
android:layout_alignParentTop="true"
android:textSize="25dp"
android:layout_alignParentStart="true"
android:layout_alignEnd="@+id/list_rune" />
------------bla bla bla -----------------
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:layout_alignTop="@+id/list_date_update"
android:layout_toLeftOf="@+id/list_rune"
android:layout_toStartOf="@+id/list_rune"
android:id="@+id/textTester" />
</RelativeLayout>
我的主要课程 -
public class MainActivity extends ListActivity implements AdapterView.OnItemLongClickListener, SharedPreferences.OnSharedPreferenceChangeListener {
private NordBase dbHelper;
private Cursor cursor;
int rage = list_row; // my custom row
-------------------on create----------------
setContentView(R.layout.activity_main);
this.getListView().setDividerHeight(2);
dbHelper = new NordBase(this);
fillData();
-----------------fillData-----------------
cursor = dbHelper.getAll();
startManagingCursor(cursor);
String[] from = new String[] { NordBase.NORD_NAME, NordBase.NORD_DESCRIPTION,
NordBase.NORD_PUNKTS, NordBase.NORD_PUNKTS_CROSS,
NordBase.NORD_DATE_CREATE, NordBase.NORD_DATE_UPDATE, NordBase.NORD_RUNE,
NordBase.NORD_IMPORTANT, NordBase.NORD_SUM };
int[] to = new int[] { R.id.list_name, R.id.list_description, R.id.list_punkts,
R.id.list_punkts_cross, R.id.list_date_create, R.id.list_date_update,
R.id.list_rune, R.id.list_important, R.id.list_sum, };
notes = new SimpleCursorAdapter(this,
rage, cursor, from, to);
setListAdapter(notes);
getListView().setOnItemLongClickListener(this);
唉,我无法访问 list_row 中的项目,为比较运算符绑定它们。对于 exp:如果 price == 0,则 textview.setvisible = false...
我尝试了 LayoutInflater,但他使视图元素与列表视图中的元素不同。 我尝试了适配器活页夹类 - 但我认为它对此没有好处。 大多数情况下我有一个错误 - 不能为“空元素”做那个......这种情况 - 看起来就像我所做的一切 - 我的程序在 list_row 中找不到 ViewById 元素。
只有一个联系方式
int[] to = new int[] { R.id.list_name, R.id.list_description, R.id.list_punkts,
R.id.list_punkts_cross, R.id.list_date_create, R.id.list_date_update,
R.id.list_rune, R.id.list_important, R.id.list_sum, };
notes = new SimpleCursorAdapter(this,
rage, cursor, from, to);
所以请帮助我 Obi-Van Kenobi,并为我的假 ENG 感到抱歉,我不确定我是否以正确的方式过去了 cod)))
【问题讨论】:
-
您能否更具体地说明问题所在?
-
我试图做到尽可能具体))我想在 list_row 中找到 ViewByID 元素。正如我在下面学习答案 - 我需要制作自定义适配器类,没有它我无法忍受)))
标签: android listview simplecursoradapter listactivity