Код не расширяет ListViewActivity, но имеет просмотр списка - PullRequest
3 голосов
/ 24 января 2012

Я знаю, что в Listviews есть много постов о флажках, и я могу честно сказать, что после прочтения большинства из них, я запутался в болящем мозге.

Мой код нерасширяет ListViewActivity, но имеет просмотр списка как часть относительного макета, который находится внутри табуляции.

Я пробовал focusable = false как для textview, так и для флажка, textview ведет себя, но флажок по-прежнему переопределяетфокус элемента списка.

Если бы мне нужен был только один текстовый просмотр, я бы пошел на андроиды, встроенные в макет, но мне нужно как минимум 6 текстовых просмотров с галочкой в ​​каждой строке.

My Main.xml это:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/tabhost_master"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent">
  <TabWidget 
    android:id="@android:id/tabs"
    android:layout_width="fill_parent"
    android:layout_height="65px"
     />  

<FrameLayout
   android:id="@android:id/tabcontent"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:paddingTop="65px">
<RelativeLayout
    android:id="@+id/tab1"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:weightSum="1" android:gravity="top" android:layout_width="fill_parent">
    <TextView android:text="Morning Set Up" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></TextView>
    <Button android:text="Set Time On" android:layout_height="wrap_content" android:id="@+id/startb" android:layout_width="wrap_content" android:layout_below="@+id/textView1" android:layout_alignParentLeft="true"></Button>
    <Button android:text="Set Time Off" android:layout_height="wrap_content" android:id="@+id/stopb" android:layout_width="wrap_content" android:layout_alignTop="@+id/startb" android:layout_alignParentRight="true"></Button>
    <Button android:layout_width="wrap_content" android:text="Set Days" android:id="@+id/mset_days" android:layout_height="wrap_content" android:layout_below="@+id/startb" android:layout_centerHorizontal="true"></Button>
    <Button android:id="@+id/confirm_m" android:layout_height="wrap_content" android:text="Confirm" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days" android:layout_alignParentLeft="true"></Button>
    <Button android:id="@+id/cancel_m" android:layout_height="wrap_content" android:text="Cancel" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days" android:layout_alignParentRight="true"></Button>
    <ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/listView1" android:layout_below="@+id/mset_days" android:layout_alignParentLeft="true" android:layout_marginTop="34dp"></ListView>
</RelativeLayout>
<RelativeLayout
    android:id="@+id/tab2"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:weightSum="1" android:gravity="top" android:layout_width="fill_parent">
    <TextView android:text="A Set Up" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/textView1_a" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></TextView>
    <Button android:text="Set Time On" android:layout_height="wrap_content" android:id="@+id/startb_a" android:layout_width="wrap_content" android:layout_below="@+id/textView1_a" android:layout_alignParentLeft="true"></Button>
    <Button android:text="Set Time Off" android:layout_height="wrap_content" android:id="@+id/stopb_a" android:layout_width="wrap_content" android:layout_alignTop="@+id/startb_a" android:layout_alignParentRight="true"></Button>
    <Button android:layout_width="wrap_content" android:text="Set Days" android:id="@+id/mset_days_a" android:layout_height="wrap_content" android:layout_below="@+id/startb_a" android:layout_centerHorizontal="true"></Button>
    <TextView android:layout_height="wrap_content" android:text="Date / Time : \n Day \n Time" android:id="@+id/dandt_a" android:layout_width="wrap_content" android:layout_below="@+id/mset_days_a" android:layout_alignRight="@+id/mset_days_a" android:layout_marginTop="30dp"></TextView>
    <TextView android:id="@+id/dandt2_a" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Along with this one as well" android:layout_below="@+id/dandt_a" android:layout_alignParentLeft="true" android:layout_marginLeft="14dp" android:layout_marginTop="44dp"></TextView>
    <TextView android:layout_height="wrap_content" android:text="To see if these text boxes clash" android:id="@+id/dandt3_a" android:layout_width="wrap_content" android:layout_centerVertical="true" android:layout_alignParentLeft="true"></TextView>
    <Button android:id="@+id/confirm_after_a" android:layout_height="wrap_content" android:text="Confirm" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days_a" android:layout_alignParentLeft="true"></Button>
    <Button android:id="@+id/cancel_after_a" android:layout_height="wrap_content" android:text="Cancel" android:layout_width="wrap_content" android:layout_alignTop="@+id/mset_days_a" android:layout_alignParentRight="true"></Button>

</RelativeLayout>


</FrameLayout>
</TabHost>

Мой макет для просмотра списка таков:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <CheckBox android:text="Cancel ?" android:focusable="false"  android:checked="false" android:layout_width="wrap_content" android:id="@+id/checkBox1" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentLeft="true"></CheckBox>
    <TextView android:layout_width="wrap_content" android:focusable="false" android:id="@+id/time_disp" android:layout_height="wrap_content" android:text="TextView" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/checkBox1" android:layout_marginLeft="16dp" android:layout_marginTop="15dp"></TextView>
    <CheckedTextView android:layout_width="wrap_content" android:focusable="false"  android:layout_height="wrap_content" android:text="CheckedTextView" android:id="@+id/checkedTextView1" android:layout_alignTop="@+id/time_disp" android:layout_alignParentRight="true" android:layout_marginRight="18dp"></CheckedTextView>

</RelativeLayout>

Мой код активности такой:

package co.uk.sheildsatmax.layout_tester;



import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;
import android.widget.CheckBox;
public class Layout_testerActivity extends Activity  {
    /** Called when the activity is first created. */
    private String[] times = {"09:10","10:10","11:20","09:10","12:20","15:30","10:12"};
    ListView lv;
    CheckBox ticked;
    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost tabhost=(TabHost)findViewById(R.id.tabhost_master);
        tabhost.setup();

        TabSpec tab1 = tabhost.newTabSpec("Tab1");
        morning_tab.setContent(R.id.tab1);
        morning_tab.setIndicator("Tab1 Setup");

        TabSpec tab2 = tabhost.newTabSpec("tab2");
        after_tab.setContent(R.id.tab2);
        after_tab.setIndicator("Tab2 Setup");

        tabhost.addTab(tab1b);
        tabhost.addTab(tab2);
        lv = (ListView)findViewById(R.id.listView1);
       // ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this,R.layout.,R.id.time_disp,times);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_lay,R.id.time_disp,times);
        lv.setItemsCanFocus(false);        // this was another test attempt
        lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // tried this and then realised it needed androids own layout to work

        lv.setAdapter(adapter);       

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplication().getApplicationContext(), "ID :"+Long.toString(arg3), Toast.LENGTH_LONG).show();


            }
        });




    }


}

Теперь я былчтение о создании отдельного класса для адаптера для корректной работы флажка, но требуется ли это, и если да, может кто-то опубликовать базовый примерДля меня использование всех этих ссылок, которые я прочитал, действительно смутило меня:

Как вы можете видеть, я читал довольно много, но они озадачили меня еще больше, и ни у одного, похоже, нет примеров без списков.Я пишу это в Android 1.6

1 Ответ

0 голосов
/ 30 января 2012

Исправлена ​​эта проблема, отчасти мое недопонимание того, как флажок работает с представлением списка, а также понимание поведения просмотра списка.

В итоге я использовал пример, приведенный в этой теме на этом форуме -> Управление несколькими флажками

С помощью этой ветки на этом форуме => [Тиканье флажков при нажатии на строку просмотра списка] [2]

Наконец, просмотр списка запомнил, какой флажок отмечен при прокрутке вверх и вниз по экрану с помощью => Сохранение состояния флажка при повторном просмотре списка

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...