如何找到一个TextView编程上ListActivity [英] How to find a TextView programmatically on ListActivity
问题描述
我有一个ListActivity,我想通过编程设置一个TextView那是我的布局里面的文字,我必须这样做我所有行。
这的TextView将显示货币辛博尔有关ListActivity的每一行的当前Locale。
code片断:
DepositoRepository回购=新DepositoRepository(本);
光标C = repo.getCursor();
适配器=新SimpleCursorAdapter(这一点,R.layout.deposito_list,C,
新的String [] {Deposito.COLUNA_VALOR,Deposito.COLUNA_DATA},
新的INT [] {R.id.tvValorDeposito,R.id.tvDataDeposito});
setListAdapter(适配器);
我要为所有行是什么:
货币moeda = Currency.getInstance(Locale.getDefault());
TextView的tvMoeda =(的TextView)findViewById(R.id.tvMoeda);
tvMoeda.setText(moeda.getSymbol(Locale.getDefault()));
您可以使用自定义适配器到您的ListView。如果你想我可以编辑我的答案,并告诉你如何做到这一点。这里的东西,可以让你在正确的轨道。改编此code到您的应用程序。
而从你的活动只是叫setListAdapter(适配器),适配器作为您的自定义适配器。
希望这有助于!
编辑:
进口java.util.Currency中;
进口java.util.Locale中;进口android.content.Context;
进口android.database.Cursor;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.CursorAdapter;
进口android.widget.TextView;公共类CustomAdapter扩展的CursorAdapter { 公共CustomAdapter(上下文的背景下,光标C){
超(背景下,C);
} @覆盖
公共无效bindView(查看视图,上下文的背景下,光标光标){
货币moeda = Currency.getInstance(Locale.getDefault());
TextView的tvMoeda =(TextView中)view.findViewById(R.your_id); //你的TextView的id在这里
tvMoeda.setText(moeda.getSymbol(Locale.getDefault()));
} @覆盖
公共查看NewView的(上下文的背景下,光标光标的ViewGroup父){
LayoutInflater吹气= LayoutInflater.from(背景);
视图V = inflater.inflate(R.layout.item,父母,FALSE); //此处布局
bindView(ⅴ,上下文,光标);
返回伏;
}}
I have a ListActivity and I want to set programmatically the text of a TextView that is inside my layout, I need to do this to all my lines.
This TextView will show the Currency Simbol for the current Locale on each line of the ListActivity.
Code snippet:
DepositoRepository repo = new DepositoRepository(this);
Cursor c = repo.getCursor();
adapter = new SimpleCursorAdapter(this, R.layout.deposito_list, c,
new String[] { Deposito.COLUNA_VALOR, Deposito.COLUNA_DATA },
new int[] { R.id.tvValorDeposito, R.id.tvDataDeposito });
setListAdapter(adapter);
What I want for all rows:
Currency moeda = Currency.getInstance(Locale.getDefault());
TextView tvMoeda = (TextView)findViewById(R.id.tvMoeda);
tvMoeda.setText(moeda.getSymbol(Locale.getDefault()));
You can use a Custom Adapter to your listView. If you want I can edit my answer and show you how to do this. Here is something that can put you on a right track. Adapt this code to your application. And from your activity just call setListAdapter(adapter), adapter being your custom adapter.
Hope this helps!
EDIT:
import java.util.Currency;
import java.util.Locale;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;
public class CustomAdapter extends CursorAdapter{
public CustomAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
Currency moeda = Currency.getInstance(Locale.getDefault());
TextView tvMoeda = (TextView)view.findViewById(R.your_id);//your textView id here
tvMoeda.setText(moeda.getSymbol(Locale.getDefault()));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.item, parent, false);//your layout here
bindView(v, context, cursor);
return v;
}
}
这篇关于如何找到一个TextView编程上ListActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!