我现在所拥有的是一个列表,当我用手指从屏幕左侧滑动时会显示该列表。我也有一个按钮,但我不知道如何使该按钮与手指做同样的动作。
我有一个主要课程,MainActivity
extends Action
和其他2个extends Fragment
课程。该按钮名为menuButton
。
这是我的代码,menuButton.setOnClickListener(new View.OnClickListener()
是我试图让这种情况发生的地方。
public class ActivityTypes extends Fragment implements BluetoothListener {
private ActivityEntity currentActivityEntity;
private ArrayList<ActivityDetalis> activityDetailsList = new ArrayList<ActivityDetalis>();
private String startDateTime = "", endDateTime = "";
private static int idLastActivity;
int activityType = 1;
private Button menuButton;
private BluetoothMeterService bluetoothMeterService;
private static final String TAG = "DeviceListActivity";
public static final String START_FROM_PAUSED_ACTIVITY_FLAG = "START_FROM_PAUSED_ACTIVITY_FLAG";
private String deviceAdress;
private View rootView;
public static boolean noMessages;
public ImageView heart;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.activity_screen, container, false);
initialization();
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = new DatabaseHandler(getActivity());
SharedPreferences settings = getActivity().getSharedPreferences(ConnectionScreen.PREFS_NAME,0);
boolean autoConnect = settings.getBoolean("autoConnect",false);
deviceAdress = settings.getString("deviceAdress","");
if (autoConnect == true) {
bluetoothMeterService = new BluetoothMeterService(new Handler());
Intent intent = new Intent(getActivity(), BluetoothMeterService.class);
intent.putExtra("deviceAdress", deviceAdress);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(deviceAdress);
bluetoothMeterService.connect(device);
Toast.makeText(getActivity(), "Already connected to " + device.getName(), Toast.LENGTH_SHORT).show();
Log.d("test", "AlreadyConnected");
}
else
{
Log.d("test","Disconnected");
}
//TODO updateDetails();
}
private void initialization(){
final Spinner spinnerOfActivities = (Spinner) rootView.findViewById(R.id.spinner_activities);
menuButton = (Button) rootView.findViewById(R.id.button_menu);
spinnerOfActivities.setAdapter(new ActivitySpinnerAdapter(getActivity(), R.layout.custom_spinner,
activities,total_images));
spinnerOfActivities.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
String selectedActivity = (String) adapterView.getAdapter().getItem(i);
activityType = 1;
for (EnumActivities.ActivitiesModeEnum act : EnumActivities.ActivitiesModeEnum.values()) {
if (act.getActivityName().equals(selectedActivity.toUpperCase())) {
activityType = act.getActivityNumber();
break;
}
};
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
spinnerOfActivities.setPopupBackgroundResource(R.color.Blue);
menuButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), MainActivity.class);
startActivity(intent);
}
});
});
@Override
public void onUpdate(ActivityDetalis activityDetalis) {
Log.e("OBSERVER ACTIVITY", activityDetalis.toString());
getActivity().runOnUiThread(new Runnable() {
public void run() {
heart.setColorFilter(getActivity().getResources().getColor(R.color.Blue));
}
});
// TODO - UI
if(start == true && pause == false)
updateUI(activityDetalis);
// TODO - ADD TO LIST
ActivityEntity activity = new ActivityEntity(activityType,startDateTime,endDateTime);
activityDetailsList.add(activityDetalis);
}
}
答案 0 :(得分:0)
如果我理解你的问题。我建议你使用Android抽屉布局。请检查此链接。
http://developer.android.com/training/implementing-navigation/nav-drawer.html
通过“打开并关闭应用程序图标”主题