Listview 项目颜色更改 onactivityResult
Listview Item color change onactivityResult
我创建了一个列表视图并在列表项上单击我正在启动 activity。我在列表视图行中有一个文本。当我在 onItemClick 上调用的 activity 完成或说 return 结果和结果代码为 RESULT_OK.
时,我想更改该文本视图的颜色
请大家帮忙
提前致谢。
这是我的代码:
HeadingListView = (ListView) findViewById(R.id.HeaderList);
adapter = new CustomHeadingAdapter(getApplicationContext(), HeadingList);
HeadingListView.setAdapter(adapter);
HeadingListView.setOnItemClickListener(this);
OnItemClickListener 代码是:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent;
switch (position){
case 0:
intent = new Intent(getApplicationContext(), Activity1.class);
intent.putExtras(AllFilledData.get(0));
startActivityForResult(intent, position);
break;
case 1:
intent = new Intent(getApplicationContext(), Activity2.class);
intent.putExtras(AllFilledData.get(1));
startActivityForResult(intent, position);
break;
case 2:
intent = new Intent(getApplicationContext(), Activity3.class);
intent.putExtras(AllFilledData.get(position));
startActivityForResult(intent, position);
break;
这是 OnActivity 结果:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 0 :
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
//Here I want to change color of TextView of listitem at position 0
}
break;
case 1:
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
//Here I want to change color of TextView of listitem at position 1
}
break;
case 2:
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
//Here I want to change color of TextView of listitem at position 2
}
break;
嗯..
首先在您的代码中的自定义适配器中添加方法。
View v = listview.getChildAt(int position);
//return 它是从列表视图顶部开始的视图定位位置。
//不是适配器项位置。
//并将视图扔给适配器。
adapter.ChangeTextViewColor(v);
public void ChangeTextViewColor(View v){TextView txt = v.childAt(int position); // or findViewbyId(int id);
txt.setTextColor(Color.parse(字符串 RGBcode)); // 或其他方式。
}
如果保持 textview 颜色使用 viewholder。
在适配器的方法 getView
中
if(items.get(position).colorchangeType == change) textview.setTextViewColor....
以及 onactivityresult 的一些变化。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 0 :
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
adapter.getItem(requestCode).colorchangeType = change;
adapter.notifysetdatachange();
//Here I want to change color of TextView of listitem at position 0
}
break;
我的英语不好......我希望能有所帮助。
我创建了一个列表视图并在列表项上单击我正在启动 activity。我在列表视图行中有一个文本。当我在 onItemClick 上调用的 activity 完成或说 return 结果和结果代码为 RESULT_OK.
时,我想更改该文本视图的颜色请大家帮忙
提前致谢。
这是我的代码:
HeadingListView = (ListView) findViewById(R.id.HeaderList);
adapter = new CustomHeadingAdapter(getApplicationContext(), HeadingList);
HeadingListView.setAdapter(adapter);
HeadingListView.setOnItemClickListener(this);
OnItemClickListener 代码是:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent;
switch (position){
case 0:
intent = new Intent(getApplicationContext(), Activity1.class);
intent.putExtras(AllFilledData.get(0));
startActivityForResult(intent, position);
break;
case 1:
intent = new Intent(getApplicationContext(), Activity2.class);
intent.putExtras(AllFilledData.get(1));
startActivityForResult(intent, position);
break;
case 2:
intent = new Intent(getApplicationContext(), Activity3.class);
intent.putExtras(AllFilledData.get(position));
startActivityForResult(intent, position);
break;
这是 OnActivity 结果:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 0 :
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
//Here I want to change color of TextView of listitem at position 0
}
break;
case 1:
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
//Here I want to change color of TextView of listitem at position 1
}
break;
case 2:
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
//Here I want to change color of TextView of listitem at position 2
}
break;
嗯.. 首先在您的代码中的自定义适配器中添加方法。
View v = listview.getChildAt(int position);
//return 它是从列表视图顶部开始的视图定位位置。 //不是适配器项位置。
//并将视图扔给适配器。
adapter.ChangeTextViewColor(v);
public void ChangeTextViewColor(View v){TextView txt = v.childAt(int position); // or findViewbyId(int id);
txt.setTextColor(Color.parse(字符串 RGBcode)); // 或其他方式。 }
如果保持 textview 颜色使用 viewholder。 在适配器的方法 getView
中if(items.get(position).colorchangeType == change) textview.setTextViewColor....
以及 onactivityresult 的一些变化。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 0 :
if(resultCode == RESULT_OK){
Bundle bundle = data.getExtras();
AllFilledData.set(requestCode, bundle);
adapter.getItem(requestCode).colorchangeType = change;
adapter.notifysetdatachange();
//Here I want to change color of TextView of listitem at position 0
}
break;
我的英语不好......我希望能有所帮助。