» »

[Android]ListView tezava

[Android]ListView tezava

KernelPanic ::

Spostovani!

A mi lahko kdo pomaga, ker na telefonu niti na simulatorju ne morem prikazati ListActivity! Pocasi obupujem, Tukaj sta xml datoteki:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#00FF00"
        android:layout_weight="1"
        android:drawSelectorOnTop="false"
    />
</LinearLayout>
ter
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp">
     <ImageView android:id="@+id/item_mainscreen_image"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_marginRight="15dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
    />
    <TextView android:id="@+id/item_mainscreen_text"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:textStyle="bold"
        android:textSize="22dp"
        android:textColor="#000000"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
    />
</LinearLayout>
Tukaj je koda:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.test;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

/**
 *
 * @author user
 */
public class CActivityMainScreen extends ListActivity
{
    private static final String m_strLogTag="CActivityMainScreen";

    private static final CItemMainScreen[] items=new CItemMainScreen[3];

    private static final int DIALOG_PRODUCT_SEARCH=1;
    private static final int DIALOG_SHOPPING_CART=2;
    private static final int DIALOG_ABOUT_APPLICATION=3;

    private static final CharSequence[] itemsProductSearch={
                                                                "Item0",
                                                                "Item1",
                                                                "Item2"
                                                            };

    private void initItems()
    {
        CActivityMainScreen.items[0]=new CItemMainScreen("",
                                                         "Izbira1");
        CActivityMainScreen.items[1]=new CItemMainScreen("",
                                                         "Izbira2");
        CActivityMainScreen.items[2]=new CItemMainScreen("",
                                                         "Izbira3");
    }   // initItems

    @Override
    public void onCreate(Bundle icicle)
    {
        try
        {
            super.onCreate(icicle);

            ListView mainScreenListView=this.getListView();

            this.initItems();
            mainScreenListView.setAdapter(new CItemMainScreenAdapter(this,
                                          R.layout.citemmainscreen,
                                          items));
        }
        catch(Exception ex)
        {
            String strClassName=ex.getClass().getName().toString();
            String strMessage=ex.getMessage().toString();

            Log.wtf(CActivityMainScreen.m_strLogTag,
                    strClassName+":"+
                    strMessage);
        }
        finally
        {
        }   // try-catch-finally
    }   // onCreate

    @Override
    public void onListItemClick(ListView parent,
                                View v,
                                int position,
                                long id)
    {
    }   // onListItemClick

    @Override
    protected Dialog onCreateDialog(int id)
    {
        switch(id)
        {
            case CActivityMainScreen.DIALOG_PRODUCT_SEARCH:
                AlertDialog.Builder adb=this.buildAlertDialog("Izberite nacin iskanja",
                                                              itemsProductSearch);
                AlertDialog ad=adb.create();

                break;
            case CActivityMainScreen.DIALOG_SHOPPING_CART:
                break;
            case CActivityMainScreen.DIALOG_ABOUT_APPLICATION:
                break;
            default:
                return null;
        }   // switch

        return null;
    }   // onCreateDialog

    private AlertDialog.Builder buildAlertDialog(final String title,
                                                 final CharSequence[] items)
    {
        try
        {
            AlertDialog.Builder adb=new AlertDialog.Builder(this);

            adb.setTitle(title);
            adb.setSingleChoiceItems(itemsProductSearch,
                                    -1,
                                    new DialogInterface.OnClickListener()
                                    {
                                        public void onClick(DialogInterface dialog,
                                                            int item)
                                        {
                                            Toast.makeText(getApplicationContext(),
                                                           itemsProductSearch[item],
                                                           Toast.LENGTH_SHORT).show();
                                            
                                        }
                                    });

            return adb;
        }
        catch(Exception ex)
        {
            String strClassName=ex.getClass().getName().toString();
            String strMessage=ex.getMessage().toString();

            Log.wtf(CActivityMainScreen.m_strLogTag,
                    strClassName+":"+
                    strMessage);
        }

        return null;
    }   // buildAlertDialog
}
. Kaj je narobe, prosim vas za pomoc, ker obupujem!!!!!! :8)

Ashrack ::

v oncreate() definiraj
setContentView()
za XML v katerem imas ta listview
....


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

Android - Začetnik

Oddelek: Programiranje
111781 (1106) hurlimannxt
»

android črta

Oddelek: Programiranje
412399 (1670) g333kk
»

[android] vstavljanje slike

Oddelek: Programiranje
71240 (1137) messi
»

[android] crash

Oddelek: Programiranje
61338 (1147) messi
»

[Android]Cudno obnasanje aplikacije in emulatorja

Oddelek: Programiranje
71309 (1138) KernelPanic

Več podobnih tem