【问题标题】:Problems with ListView and layoutListView 和布局的问题
【发布时间】:2014-12-31 18:35:32
【问题描述】:

我正在使用 android studio,我正在尝试遵循本指南:http://tinyurl.com/oelsg7o,它实现了数据库,但我遇到了“R.layout.listactivity_row 问题。
本指南没有解释如何以及在何处插入“listactiviry_row” 你能帮帮我吗?

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

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

这是 main_activiry.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文件放入layout-Folder...
  • 我只有 main_layout.xml,它在 loyout 文件夹中!

标签: android list sqlite listview view


【解决方案1】:

这是您需要的行文件,在布局文件夹中创建一个新的 xml 文件作为 listactivity_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>

【讨论】:

  • 是的,可以,但是当我点击“salva”时不显示数据库项目!
  • @GentooAntoo 因为它无论如何都没有保存到数据库,请检查代码两次,如果我的回答对您有帮助,请接受它作为正确答案
  • @GentooAntoo Put adapter.notifyDataSetChanged();作为 salva() 方法中 if { } 块的最后一行
  • 我听从了您的建议,但仍然没有显示任何内容!
  • @GentooAntoo尝试打印salve方法中保存的数据,检查logcat数据是否进入数据库
猜你喜欢
  • 1970-01-01
  • 2019-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多