mirror of
https://github.com/nerzhul/nrz-androidlib.git
synced 2025-06-07 16:06:21 +00:00
Add onclicklistener on AndroidAccountAdapter. This permit to launch another activity based on this account
This commit is contained in:
parent
b126a568e0
commit
4bf0073d6f
@ -3,9 +3,13 @@ package fr.nrz.androidlib.adapters;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
@ -15,13 +19,17 @@ public class AndroidAccountAdapter extends ArrayAdapter<Account> {
|
||||
private final ArrayList<Account> _accounts;
|
||||
private static int _itemLayout;
|
||||
private static int _accountFieldId;
|
||||
private final Activity _activity;
|
||||
Class<?> _newActivityClass;
|
||||
|
||||
public AndroidAccountAdapter(final Context context, final int resource,
|
||||
final ArrayList<Account> objects, final int itemLayout, final int accountFieldId) {
|
||||
super(context, resource, objects);
|
||||
public AndroidAccountAdapter(final Activity activity, final int resource,
|
||||
final ArrayList<Account> objects, final int itemLayout, final int accountFieldId, final Class<?> newActivityClass) {
|
||||
super(activity.getBaseContext(), resource, objects);
|
||||
_accounts = objects;
|
||||
_itemLayout = itemLayout;
|
||||
_accountFieldId = accountFieldId;
|
||||
_activity = activity;
|
||||
_newActivityClass = newActivityClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,7 +45,15 @@ public class AndroidAccountAdapter extends ArrayAdapter<Account> {
|
||||
if (account != null) {
|
||||
final TextView label = (TextView) v.findViewById(_accountFieldId);
|
||||
if (label != null) {
|
||||
label.setText(account.name + " -->");
|
||||
label.setText(account.name + " >");
|
||||
label.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
final Bundle bdl = new Bundle();
|
||||
bdl.putString("account",account.name);
|
||||
_activity.startActivity(new Intent(_activity, _newActivityClass), bdl);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user