Android 如何在基本适配器中将文本设置为文本视图?

Android 如何在基本适配器中将文本设置为文本视图?,android,Android,我是android的初学者,编写这个简单的适配器: public class CustomAdapter extends BaseAdapter{ public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, String[] prgmImages) { //Do something... and dont write this code } @Override

我是android的初学者,编写这个简单的适配器:

public class CustomAdapter extends BaseAdapter{

    public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, String[] prgmImages) {   
        //Do something... and dont write this code
    }
    @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
        //Want write this code>>>>TextView1.SetText("Hello");

    }

}

并使用以下行调用主活动中的适配器:

 lv=(ListView) findViewById(R.id.myLIST);
                lv.setAdapter(new CustomAdapter(MainActivity.this, prgmNameList,prgmImages));

我想在自定义adepter调用和处理某些事情时,将结果写入主活动文本视图。我如何才能做到这一点?谢谢。

有一个界面

public interface EventListener
{
   public void onEvent(String result);
}
然后在构造函数中

 EventListener eventListener; 
 public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, String[] prgmImages) {   
    //Do something... and dont write this code
    eventListener = (EventListener) mainActivity;
}
getView

 @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
     evenListener.onEvent("Hello");

}
然后在活动中

public class YourActivity extends Activity implements EventListener
然后

有接口

public interface EventListener
{
   public void onEvent(String result);
}
然后在构造函数中

 EventListener eventListener; 
 public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, String[] prgmImages) {   
    //Do something... and dont write this code
    eventListener = (EventListener) mainActivity;
}
getView

 @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
     evenListener.onEvent("Hello");

}
然后在活动中

public class YourActivity extends Activity implements EventListener
然后

有接口

public interface EventListener
{
   public void onEvent(String result);
}
然后在构造函数中

 EventListener eventListener; 
 public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, String[] prgmImages) {   
    //Do something... and dont write this code
    eventListener = (EventListener) mainActivity;
}
getView

 @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
     evenListener.onEvent("Hello");

}
然后在活动中

public class YourActivity extends Activity implements EventListener
然后

有接口

public interface EventListener
{
   public void onEvent(String result);
}
然后在构造函数中

 EventListener eventListener; 
 public CustomAdapter(MainActivity mainActivity, String[] prgmNameList, String[] prgmImages) {   
    //Do something... and dont write this code
    eventListener = (EventListener) mainActivity;
}
getView

 @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
     evenListener.onEvent("Hello");

}
然后在活动中

public class YourActivity extends Activity implements EventListener
然后


试试这个,这是一种方法,你也可以找到不同的方法

活动
类中创建函数

public void refreshData(){
    //CODE TO SET TEXT
}
并使用上下文从适配器调用函数

在适配器类中,像这样调用

((MainActivity)context).refreshData();

您也可以使用接口,但在这种情况下,无需使用该接口,使用
上下文
就可以了。

试试这个,这是一种方法,您也可以找到不同的方法

活动
类中创建函数

public void refreshData(){
    //CODE TO SET TEXT
}
并使用上下文从适配器调用函数

在适配器类中,像这样调用

((MainActivity)context).refreshData();

您也可以使用接口,但在这种情况下,无需使用该接口,使用
上下文
就可以了。

试试这个,这是一种方法,您也可以找到不同的方法

活动
类中创建函数

public void refreshData(){
    //CODE TO SET TEXT
}
并使用上下文从适配器调用函数

在适配器类中,像这样调用

((MainActivity)context).refreshData();

您也可以使用接口,但在这种情况下,无需使用该接口,使用
上下文
就可以了。

试试这个,这是一种方法,您也可以找到不同的方法

活动
类中创建函数

public void refreshData(){
    //CODE TO SET TEXT
}
并使用上下文从适配器调用函数

在适配器类中,像这样调用

((MainActivity)context).refreshData();

您也可以使用接口,但在这种情况下,不需要使用该接口,使用
context
可以满足您的需要。

您可以使用接口作为对活动的回调。@Raghunandan我如何使用它?发布了一个答案看看您可以使用接口作为对活动的回调。@Raghunandan我如何使用它?发布了一个答案看看您可以使用接口作为对活动的回调。@Raghunandan如何可以我使用它?发布了一个答案看看你可以使用接口作为活动的回调。@Raghunandan我如何使用它?发布了一个答案看看这个