收藏夹分类单选改成下拉列表
This commit is contained in:
@@ -41,6 +41,8 @@ import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
@@ -50,10 +52,10 @@ import java.util.ArrayList;
|
||||
public class FavoriteActivity extends Activity {
|
||||
EditText editText;
|
||||
ImageButton imageButton_clear;
|
||||
RadioGroup radioGroup;
|
||||
InputMethodManager IMM;
|
||||
ListView listView;
|
||||
SimpleCursorAdapter adapter;
|
||||
Spinner spinner;
|
||||
int position = 0;
|
||||
|
||||
@Override
|
||||
@@ -67,12 +69,23 @@ public class FavoriteActivity extends Activity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
editText.setText("");
|
||||
IMM.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
||||
}
|
||||
});
|
||||
imageButton_clear.setVisibility(View.GONE);
|
||||
editText = (EditText) findViewById(R.id.editText);
|
||||
editText.addTextChangedListener(new EditChangedListener());
|
||||
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
|
||||
spinner = (Spinner) findViewById(R.id.spinner);
|
||||
spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
|
||||
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "spinner: " + arg2);
|
||||
IMM.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
||||
String s = arg0.getItemAtPosition(arg2).toString();
|
||||
search(1, s);
|
||||
}
|
||||
public void onNothingSelected(AdapterView<?> arg0) {
|
||||
}
|
||||
});
|
||||
genCategory();
|
||||
|
||||
listView = (ListView) findViewById(R.id.listView1);
|
||||
@@ -110,9 +123,6 @@ public class FavoriteActivity extends Activity {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
RadioButton radioButton = (RadioButton) radioGroup.getChildAt(0);
|
||||
radioButton.performClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,8 +156,6 @@ public class FavoriteActivity extends Activity {
|
||||
helper.insert("category", values);
|
||||
IMM.hideSoftInputFromWindow(editText1.getWindowToken(), 0);
|
||||
genCategory();
|
||||
RadioButton radioButton = (RadioButton) radioGroup.getChildAt(0);
|
||||
radioButton.performClick();
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "分类已存在", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@@ -159,10 +167,7 @@ public class FavoriteActivity extends Activity {
|
||||
case 1:
|
||||
builder = new AlertDialog.Builder(FavoriteActivity.this);
|
||||
builder.setIcon(android.R.drawable.ic_menu_edit);
|
||||
RadioButton radioButton = (RadioButton) findViewById(radioGroup.getCheckedRadioButtonId());
|
||||
if (radioButton == null)
|
||||
break;
|
||||
final String title = radioButton.getText().toString();
|
||||
final String title = spinner.getSelectedItem().toString();
|
||||
if (title.equals(""))
|
||||
break;
|
||||
builder.setTitle(title);
|
||||
@@ -181,8 +186,6 @@ public class FavoriteActivity extends Activity {
|
||||
db.update("category", values, "category = '" + title + "'", null);
|
||||
db.update(helper.TableName, values, "category = '" + title + "'", null);
|
||||
genCategory();
|
||||
RadioButton radioButton = (RadioButton) radioGroup.getChildAt(0);
|
||||
radioButton.performClick();
|
||||
IMM.hideSoftInputFromWindow(editText_rename.getWindowToken(), 0);
|
||||
}
|
||||
});
|
||||
@@ -196,8 +199,6 @@ public class FavoriteActivity extends Activity {
|
||||
values.put("category", "");
|
||||
db.update(helper.TableName, values, "category = '" + title + "'", null);
|
||||
genCategory();
|
||||
RadioButton radioButton = (RadioButton) radioGroup.getChildAt(0);
|
||||
radioButton.performClick();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("取消", null);
|
||||
@@ -334,11 +335,11 @@ public class FavoriteActivity extends Activity {
|
||||
int i = db.update(DBHelper.TableName, values, "_id = " + sid, null);
|
||||
if (i != -1) {
|
||||
IMM.hideSoftInputFromWindow(editText_title.getWindowToken(), 0);
|
||||
RadioButton radioButton = (RadioButton) findViewById(radioGroup.getCheckedRadioButtonId());
|
||||
if (radioButton == null)
|
||||
String s = spinner.getSelectedItem().toString();
|
||||
if (s.equals(""))
|
||||
search(0, editText.getText().toString());
|
||||
else
|
||||
search(1, radioButton.getText().toString());
|
||||
search(1, s);
|
||||
try { //关闭
|
||||
field.set(dialog, true);
|
||||
dialog.dismiss();
|
||||
@@ -396,16 +397,6 @@ public class FavoriteActivity extends Activity {
|
||||
return true;
|
||||
}
|
||||
|
||||
class RadioButtonOnClickListener implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
IMM.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
||||
RadioButton radioButton = (RadioButton) v;
|
||||
String s = radioButton.getText().toString();
|
||||
search(1, s);
|
||||
}
|
||||
}
|
||||
|
||||
void search(int type, String s) {
|
||||
DBHelper helper = new DBHelper(this);
|
||||
Cursor cursor1 = null;
|
||||
@@ -445,17 +436,16 @@ public class FavoriteActivity extends Activity {
|
||||
|
||||
void genCategory() {
|
||||
IMM.hideSoftInputFromWindow(editText.getWindowToken(), 0);
|
||||
radioGroup.removeAllViews();
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
DBHelper helper = new DBHelper(this);
|
||||
Cursor cursor = helper.category();
|
||||
if (cursor != null) {
|
||||
while (cursor.moveToNext()) {
|
||||
String s = cursor.getString(cursor.getColumnIndex("category"));
|
||||
RadioButton radioButton = new RadioButton(this);
|
||||
radioButton.setText(s);
|
||||
radioButton.setOnClickListener(new RadioButtonOnClickListener());
|
||||
radioGroup.addView(radioButton);
|
||||
list.add(s);
|
||||
}
|
||||
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, list);
|
||||
spinner.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,7 +466,6 @@ public class FavoriteActivity extends Activity {
|
||||
imageButton_clear.setVisibility(View.VISIBLE);
|
||||
}
|
||||
search(0, s.toString());
|
||||
radioGroup.clearCheck();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user