mirror of
				https://github.com/nerzhul/nrz-androidlib.git
				synced 2025-10-31 09:27:13 +00:00 
			
		
		
		
	Add AndroidAccountAdapter which permit to generate an account listview directly by creating this adapter and passing a android listview resource and item layout
This commit is contained in:
		
							parent
							
								
									f4497ce993
								
							
						
					
					
						commit
						ba2b4a8980
					
				
							
								
								
									
										47
									
								
								src/fr/nrz/androidlib/adapters/AndroidAccountAdapter.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								src/fr/nrz/androidlib/adapters/AndroidAccountAdapter.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,47 @@ | ||||
| package fr.nrz.androidlib.adapters; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.content.Context; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.ArrayAdapter; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| public class AndroidAccountAdapter extends ArrayAdapter<Account> { | ||||
| 
 | ||||
| 	private final ArrayList<Account> _accounts; | ||||
| 	private static int _itemLayout; | ||||
| 	private static int _accountFieldId; | ||||
| 
 | ||||
| 	public AndroidAccountAdapter(final Context context, final int resource, | ||||
| 			final ArrayList<Account> objects, final int itemLayout, final int accountFieldId) { | ||||
| 		super(context, resource, objects); | ||||
| 		_accounts = objects; | ||||
| 		_itemLayout = itemLayout; | ||||
| 		_accountFieldId = accountFieldId; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public View getView(final int position, final View convertView, final ViewGroup parent) { | ||||
| 		View v = convertView; | ||||
| 		if (v == null) { | ||||
| 			final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||||
| 			v = inflater.inflate(_itemLayout, null); | ||||
| 		} | ||||
| 
 | ||||
| 		final Account account = _accounts.get(position); | ||||
| 
 | ||||
| 		if (account != null) { | ||||
| 			final TextView label = (TextView) v.findViewById(_accountFieldId); | ||||
| 			if (label != null) { | ||||
| 				label.setText(account.name + "  -->"); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return v; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user