Я привязываю, чтобы установить текстовое представление внутри моего ListView видимым в зависимости от другой переменной. Но когда я пытаюсьНастройка TextView видима (или ушла) в ListView
TextView sdate;
TextView stime;
sdate= (TextView) findViewById(R.id.date);
stime= (TextView) findViewById(R.id.time);
Кажется, что он не может найти 2 в макете?
Из того, что я собираю, должно быть что-то перед findViewbyId(), но я не уверен в чем. Макет элементов в списке выполняется с помощью list_item.xml. , Обрабатывающим все этот код:
ListAdapter adapter;
if(add.equals("Event")){
stime.setVisibility(View.VISIBLE);
sdate.setVisibility(View.VISIBLE);
adapter = new SimpleAdapter(
AllSpotsActivity.this, spotsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME, "sdistance","dateof","timeof" }, new int[] {
R.id.pid, R.id.name, R.id.distance, R.id.date, R.id.time});
}else{
adapter = new SimpleAdapter(
AllSpotsActivity.this, spotsList,
R.layout.list_item, new String[] { TAG_PID,
TAG_NAME, "sdistance" }, new int[] {
R.id.pid, R.id.name, R.id.distance });
}
Спасибо заранее,
Тайлер
EDIT:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/gradient_background"
>
<!-- Product id (pid) - will be HIDDEN - used to pass to other activity -->
<TextView
android:id="@+id/pid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<!-- Name Label -->
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17dip"
android:textStyle="bold" />
<!-- Name Label -->
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="6dip"/>
<TextView
android:id="@+id/date"
android:layout_below="@id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="12dip"
android:visibility="gone"/>
<TextView
android:id="@+id/time"
android:layout_below="@id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="6dip"
android:visibility="gone"/>
</RelativeLayout>
EDIT 2: Я также попытался с помощью лв .findViewById(), потому что lv = getListView(); Но это тоже не сработало.
Опубликовать свой xml, где вы определяете текст. – owe