搜索框不显示

时间:2013-12-15 22:16:35

标签: android android-layout

我已在我的应用中实施了搜索选项,但它没有显示。我的代码中没有任何错误警告,除了“错误设置焦点为:org.eclipse.e4.ui.model.application.ui.basic.impl.PartImpl MainActivity.java”。请告诉我解决这个问题。

这是MainActivity代码:

package com.example.kamuskomputer;

import java.util.List;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class MainActivity extends Activity implements TextWatcher, OnItemClickListener
{
    private EditText search;
    private ListView lv;
    private DatabaseHelper dbHelper;
    private ArrayAdapter<Kamus> adapter;
    private List<Kamus> ListKamus;

    protected void oncreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        lv = (ListView) findViewById(R.id.lv_data);
        lv.setEmptyView(findViewById(R.id.empty));
        search = (EditText) findViewById(R.id.search);

        dbHelper = DatabaseHelper.getInstance(this);

        setData();

        search.addTextChangedListener(this);
        lv.setOnItemClickListener(this);
    }

    private void setData()
    {
        ListKamus = dbHelper.getAllKamus();

        adapter = new ArrayAdapter<Kamus>(this, android.R.layout.simple_expandable_list_item_1, ListKamus);
        lv.setAdapter(adapter);
    }

    @Override
    public void afterTextChanged(Editable arg0)
    {
    }

    @Override
    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
    {
    }

    @Override
    public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3)
    {
        adapter.getFilter().filter(s.toString());
    }

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id)
    {
        Bundle b = new Bundle();
        b.putString("istilah", adapter.getItem(position).getIstilah());
        b.putString("arti", adapter.getItem(position).getArti());

        Intent i = new Intent(this, ArtiActivity.class);
        i.putExtras(b);
        startActivity(i);
    }
    }

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

<EditText 
    android:id="@+id/search"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:drawableRight="@android:drawable/ic_search_category_default"
    android:hint="@string/cari"/>

<ListView 
    android:id="@+id/lv_data"
    android:layout_width="match_parent"
    android:layout_height="match_parent"    
    android:layout_below="@id/search"/>

<TextView
    android:id="@+id/empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/lv_data"
    android:layout_marginLeft="20dp"
    android:text="@string/nol"/>
</RelativeLayout>

图形布局ScreenShot http://bugar.xtgem.com/Graphical%20Layout.PNG

在AVD屏幕截图上运行 http://bugar.xtgem.com/Run%20on%20AVD.PNG

0 个答案:

没有答案