私は自分のアプリを自動検索したいと思っています。
これは私のアプリです。
カスタム検索ビューで自動検索する方法
私のアプリ:
そして私は、私はこのようにしたい私のアプリは、この
ようにしたい:
しかし、どうやって ?誰でも助けてくれますか?
これは私のコード
あるMainActivity.classは
package com.skholingua.android.searchview;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SearchView;
public class MainActivity extends Activity implements
SearchView.OnQueryTextListener {
String[] stateList;
String[] anotherStringArray;
private SearchView searchView;
private ListView listView;
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
searchView = (SearchView) findViewById(R.id.searchView1);
listView = (ListView) findViewById(R.id.listView1);
stateList = getResources().getStringArray(R.array.stateList);
anotherStringArray = getResources().getStringArray(R.array.anotherStringArray);
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, stateList);
listView.setAdapter(adapter);
listView.setTextFilterEnabled(true);
// Sets the default or resting state of the search field.
// If true, a single search icon is shown by default and
// expands to show the text field and other buttons when pressed
//searchView.setIconifiedByDefault(false);
searchView.setOnQueryTextListener(this);
// Sets the hint text to display in the query text field
//searchView.setQueryHint("State Name");
int searchPlateId = searchView.getContext().getResources()
.getIdentifier("android:id/search_plate", null, null);
View searchPlateView = searchView.findViewById(searchPlateId);
if (searchPlateView != null) {
searchPlateView.setBackgroundColor(Color.TRANSPARENT);
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String stateName = listView.getAdapter().getItem(position).toString();
int pos=0;
for(int i=0;i<stateList.length;i++)
{
if(stateList[i].equals(stateName))
{
pos=i;
break;
}
}
// Put selected state to intent.
Intent intent = new Intent(MainActivity.this, NextActivity.class);
intent.putExtra("selectedState", stateName);
intent.putExtra("anotherStringArray", anotherStringArray[pos]);
startActivity(intent);
}
});
}
@Override
public boolean onQueryTextChange(String newText) {
android.widget.Filter filter = adapter.getFilter();
if (TextUtils.isEmpty(newText)) {
filter.filter("");
} else {
filter.filter(newText);
}
return true;
}
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity.xmリットル
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:focusableInTouchMode="true"
tools:context="com.skholingua.android.searchview.MainActivity" >
<SearchView
android:id="@+id/searchView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="@drawable/search_view_border"
android:iconifiedByDefault="false"
android:padding="2dp"
android:queryHint="Search...."
android:layout_alignParentTop="true" >
</SearchView>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/searchView1"
android:layout_centerHorizontal="true" >
</ListView>
</RelativeLayout>
ありがとうございました。私はすでにそれを修正しました。しかし、今私の問題は、どのようにAutoCompleteTextViewにXを置くことができますか? –
私はあなたのコメントを理解できませんでした。私たちは何をX、なぜあなたはそれを置いているのですか、どこに置いていますか? –
このような意味で、このリンクをクリックするだけです。https://i.stack.imgur.com/Ya6kT.jpg –