My project contains listView (homelistView) which contains a button (btnList) .
When I click the (btnList) button, it should go to another action. I tried a lot, but I did not find a good example.
Please offer me a good example.
Below is my code:
Here is my list contains a button. When a button is pressed, it should go into another activity.
homempleb.xml before using this code in xml. buttonlist worked fine for me according to Mojit's pattern of faith
<ListView android:id="@+id/homelistView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.04" android:dividerHeight="0dip" > </ListView>
homempleb.xml Currently I have added a scroll index to my list and changed the code as shown below. Listbutton is not working for me right now. Plz help me
<com.woozzu.android.widget.IndexableListView android:id="@+id/homelistView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.04" android:dividerHeight="0dip" > </com.woozzu.android.widget.IndexableListView>
MainActivity.java
public class MainActivity extends Activity implements SearchView.OnQueryTextListener, SearchView.OnCloseListener { private ListView listView; // private IndexableListView listView; private SearchView search; EfficientAdapter objectAdapter; // EfficientAdapter2 objectAdapter1; int textlength = 0; private CheckBox checkStat, checkRoutine, checkTat; private ArrayList<Patient> patientListArray; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.homempleb); Log.i("scan", " txtScanResult "); ActionItem nextItem = new ActionItem(); final QuickAction quickAction = new QuickAction(this, QuickAction.VERTICAL); quickAction.addActionItem(nextItem); quickAction.setOnDismissListener(new QuickAction.OnDismissListener() { @Override public void onDismiss() { Toast.makeText(getApplicationContext(), "Dismissed", Toast.LENGTH_SHORT).show(); } }); search = (SearchView) findViewById(R.id.searchView1); search.setIconifiedByDefault(false); search.setOnQueryTextListener(this); search.setOnCloseListener(this); search.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { quickAction.show(v); } }); checkStat = (CheckBox) findViewById(R.id.checkBoxStat); checkRoutine = (CheckBox) findViewById(R.id.checkBoxRoutine); checkTat = (CheckBox) findViewById(R.id.checkBoxTat); checkStat.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (((CheckBox) v).isChecked()) { checkStat.setChecked(true); Toast.makeText(MainActivity.this, "STAT", Toast.LENGTH_SHORT).show(); checkRoutine.setChecked(false); checkTat.setChecked(false); } } }); checkRoutine.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (((CheckBox) v).isChecked()) { checkRoutine.setChecked(true); Toast.makeText(MainActivity.this, "ROUTINE", Toast.LENGTH_SHORT).show(); checkStat.setChecked(false); checkTat.setChecked(false); } } }); checkTat.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (((CheckBox) v).isChecked()) { checkTat.setChecked(true); Toast.makeText(MainActivity.this, "TAT Effeciency", Toast.LENGTH_SHORT).show(); checkRoutine.setChecked(false); checkStat.setChecked(false); } } }); // listView = (IndexableListView) findViewById(R.id.homelistView); listView = (ListView) findViewById(R.id.homelistView); listView.setTextFilterEnabled(true); listView.setFastScrollEnabled(true); listView.setFastScrollAlwaysVisible(true); objectAdapter = new EfficientAdapter(this); listView.setAdapter(objectAdapter); Button refreshButton = (Button) findViewById(R.id.refreshButton); refreshButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // objectAdapter1 = new EfficientAdapter2(MainActivity.this); objectAdapter = new EfficientAdapter(MainActivity.this);// adapter // with // new // data listView.setAdapter(objectAdapter); Log.i("notifyDataSetChanged", "data updated"); // objectAdapter1.notifyDataSetChanged(); objectAdapter.notifyDataSetChanged(); } }); } @Override public boolean onClose() { return false; } @Override public boolean onQueryTextChange(String newText) { return false; } @Override public boolean onQueryTextSubmit(String query) { return false; }
}
EfficientAdapter.JAVA
public class EfficientAdapter extends BaseAdapter implements SectionIndexer { private String mSections = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ArrayList<Patient> patientListArray; private LayoutInflater mInflater; private Context context; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); this.context = context; String patientListJson = CountriesList.jsonData; JSONObject jssson; try { jssson = new JSONObject(patientListJson); patientListJson = jssson.getString("PostPatientDetailResult"); } catch (JSONException e) { e.printStackTrace(); } Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray Jarray = parser.parse(patientListJson).getAsJsonArray(); patientListArray = new ArrayList<Patient>(); for (JsonElement obj : Jarray) { Patient patientList = gson.fromJson(obj, Patient.class); patientListArray.add(patientList); Log.i("patientList", patientListJson); } } public void sortMyData() {
android android-layout android-intent android-listview
Rao's Sep 10 2018-12-12T00: 00Z
source share