我有一个显示我的数组数据列表和删除按钮的微调器。我想要做的是当我单击删除按钮时,它会自动删除选定的微调器值,但我不确定如何执行此操作。
在删除按钮单击功能中,再次调试我的活动后删除了选定的微调器值,但我想在单击删除按钮时自动删除选定的微调器值。
package quesansw.the1;
import java.util.ArrayList;
import android.app.Activity;
import android.app.Dialog;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.NetworkInfo.State;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.AdapterView.OnItemSelectedListener;
public class View1 extends Activity {
SQLiteDatabase db;
ArrayAdapter adapter;
private String array_spinner[];
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = openOrCreateDatabase("mydatabase.db",
SQLiteDatabase.CREATE_IF_NECESSARY, null);
final Dialog d1 = new Dialog(this);
Window window = d1.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
//d1.setTitle("Login");
d1.setContentView(R.layout.view);
d1.show();
Button Click = (Button) d1.findViewById(R.id.Click);
Button Save = (Button) d1.findViewById(R.id.Save);
Button Delete = (Button) d1.findViewById(R.id.Delete);
ArrayList<String> list = new ArrayList<String>();
Cursor cursor = db.rawQuery("select * from records", null);
list.add("");
if (cursor.moveToFirst())
{
do
{
list.add(cursor.getString(0));
}
while (cursor.moveToNext());
}
/*array_spinner=new String[20];
array_spinner[0]=list.get(0);*/
Spinner s = (Spinner) d1.findViewById(R.id.tittle_spinner);
adapter = new ArrayAdapter<Object>(this,android.R.layout.simple_spinner_item, list.toArray());
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter);
/*Save.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Spinner s = (Spinner) d1.findViewById(R.id.tittle_spinner);
String str = s.getSelectedItem().toString();
System.out.println("********"+str);
Cursor cur1=db.rawQuery("select * from records where tittle='"+str+"' ",null);
cur1.moveToNext();
String str1=cur1.getString(1);
EditText ans = (EditText) d1.findViewById(R.id.text);
ans.setText(str1);
}
});*/
Delete.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Spinner s = (Spinner) d1.findViewById(R.id.tittle_spinner);
String str = s.getSelectedItem().toString();
db.execSQL("delete from records where tittle='"+str+"' ");
}
});
Click.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Spinner s = (Spinner) d1.findViewById(R.id.tittle_spinner);
String str = s.getSelectedItem().toString();
System.out.println("********"+str);
Cursor cur1=db.rawQuery("select * from records where tittle='"+str+"' ",null);
cur1.moveToNext();
String str1=cur1.getString(1);
EditText ans = (EditText) d1.findViewById(R.id.text);
ans.setText(str1);
}
});
}
}
1)这是我的活动截图
2)另一个带有微调器值的屏幕截图: