我在Android健身应用程序中创建了一个expandablelistview,当按下练习时,显示练习和描述的图像,但是我想在每个图像下面添加一个按钮。 怎么办呢?
.java代码
package com.example.myfitnessbuddy;
import java.util.ArrayList;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ExpandableListView;
public class ChestActivity extends ActionBarActivity
{
private ExpandListAdapter ExpAdapter;
private ArrayList<Group> ExpListItems;
private ExpandableListView ExpandList;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chest);
ExpandList = (ExpandableListView) findViewById(R.id.expList);
ExpListItems = SetStandardGroups();
ExpAdapter = new ExpandListAdapter(ChestActivity.this, ExpListItems);
ExpandList.setAdapter(ExpAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.chest, 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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}
public ArrayList<Group> SetStandardGroups() {
String[] input_names = {"Bench Press (Bands)","Bench Press (Barbell)","Bench Press Close Grip (Barbell)"
,"Bench Press (Dumbbell)","Bench Press (Machine)","Bent Over Crossover"
,"Decline Chest Press (Machine)","Fly (Cable)","Fly (Dumbbell)"
,"Incline Chest Press (Dumbbell)","Pec Deck","Push-up"
,"Push-up Elevated Feet"};
String[] info_sections = {"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii, deltoids"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii, deltoids"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii, deltoids"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii, deltoids"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii, deltoids"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, deltoids"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii, deltoids"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii"
,"Primary Type: Chest /n Muscle(s) worked: pectoralis, triceps brachii, deltoids"};
int previews[] = {R.drawable.bench_press_bands,R.drawable.bench_press_barbell,R.drawable.bench_press_close_grip
,R.drawable.bench_press_dumbbell,R.drawable.bench_press_machine,R.drawable.bent_over_crossover
,R.drawable.decline_chest_press_machine,R.drawable.fly_cable,R.drawable.fly_dumbbell
,R.drawable.incline_chest_press_dumbbell,R.drawable.pec_deck,R.drawable.push_up
,R.drawable.push_up_elevated_feet};
ArrayList<Group> list = new ArrayList<Group>();
ArrayList<Child> child_list;
int a=0;
for(String input_name:input_names)
{
Group input = new Group();
input.setName(input_name);
child_list = new ArrayList<Child>();
Child child = new Child();
child.setName(info_sections[a]);
child.setImage(previews[a]);
child_list.add(child);
input.setItems(child_list);
list.add(input);
a++;
}
return list;
}
public void selectExercise(View view)
{
/*Intent intent = new Intent(this, ExerciseActivity.class);
switch (view.getId()) {
case (R.id.basics_ui):
intent = new Intent(this, BasicsUIActivity.class);
break;
case (R.id.basics_input):
intent = new Intent(this, BasicsInputActivity.class);
break;
default:
intent = new Intent(this, ExerciseActivity.class);
break;
}
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);*/
}
}
.xml file
<LinearLayout 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:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/chest"
android:padding="20dp"
android:gravity="center"
android:background="#333"
android:textColor="#eee"/>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/expList"
android:layout_gravity="center_horizontal"/>
</LinearLayout>