Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ListView和布局的问题_Android_List_Sqlite_Listview_View - Fatal编程技术网

Android ListView和布局的问题

Android ListView和布局的问题,android,list,sqlite,listview,view,Android,List,Sqlite,Listview,View,我使用的是android studio,我试图遵循以下指南:这实现了数据库,但我在“R.layout.listactivity\u行”中遇到了问题 本指南没有解释如何以及在何处插入“ListActivity_行” 你能帮我吗 @Override public View newView(Context ctx, Cursor arg1, ViewGroup arg2) { View v=getLayoutInflater().inflate(R.layout.listactiv

我使用的是android studio,我试图遵循以下指南:这实现了数据库,但我在“R.layout.listactivity\u行”中遇到了问题
本指南没有解释如何以及在何处插入“ListActivity_行” 你能帮我吗

@Override
public View newView(Context ctx, Cursor arg1, ViewGroup arg2)
{

         View v=getLayoutInflater().inflate(R.layout.listactivity_row, null);
         return v;
}  
这是main_activity.xml

<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="400dp"
xmlns:android="http://schemas.android.com/apk/res/android">


<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:id="@+id/oggetto"
    android:hint="Oggetto"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginRight="53dp"
    android:layout_marginTop="20dp" />

<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:id="@+id/testo"
    android:hint="testo"
    android:layout_below="@+id/oggetto"
    android:layout_alignLeft="@+id/oggetto"
    android:layout_alignStart="@+id/oggetto"
    android:layout_marginRight="53dp" />

<EditText
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:id="@+id/data"
    android:hint="data"
    android:layout_below="@+id/testo"
    android:layout_alignLeft="@+id/testo"
    android:layout_alignStart="@+id/testo" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="salva"
    android:id="@+id/button"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginTop="150dp"
    android:layout_marginLeft="150dp" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="200dp"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:weightSum="1">

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:id="@+id/txt_subject"
        android:hint="subject" />

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:id="@+id/txt_date"
        android:layout_marginLeft="110dp"
        android:layout_marginTop="-16dp"
        android:hint="data" />


    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:src="@android:drawable/ic_menu_delete"
        android:id="@+id/btn_delete"
        android:layout_gravity="right"
        android:layout_marginRight="50dp"
        android:layout_marginTop="-10dp" />

    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView" />
</LinearLayout>


这是您需要的行文件,在布局文件夹中创建一个新的xml文件,名为listactivity\u row.xml 然后在该文件中复制粘贴到下面的代码

<RelativeLayout
        android:layout_height="wrap_content"
        android:layout_width="400dp"
        xmlns:android="http://schemas.android.com/apk/res/android">
     <LinearLayout 
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:padding="5dp"
        android:layout_toLeftOf="@+id/btn_delete"
        android:orientation="vertical">
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/big_textstyle"
        android:id="@+id/txt_subject"/>
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/small_textstyle"
        android:id="@+id/txt_date"/>
    </LinearLayout>
    <ImageButton 
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentRight="true"
         android:layout_centerVertical="true"
         android:src="@android:drawable/ic_menu_delete"
         android:id="@+id/btn_delete"
        />
</RelativeLayout>


将任何布局xml文件放在
布局
-文件夹中…我只有main_Layout.xml,它在loyout文件夹中!是的,工作正常,但当我单击“salva”时“不显示数据库项目@GentooAntoo因为它无论如何都不会保存到数据库中,请检查代码两次,如果我的回答对您有帮助,请接受它为正确的answer@GentooAntooPut adapter.notifyDataSetChanged();作为salva()方法中if{}块的最后一行,我遵循了您的建议,但仍然没有显示任何内容@GENTOOANTO若要打印正在以salve方法保存的数据,请检查logcat是否将数据存入数据库