onactivityresult方法里面的数为什么其他方法用不了

hellofenny hellofenny 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
package lee.demo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.os.Build;


public class MainActivity extends Activity {
public static String name;
Button button01;
ListView listview;
TextView textview;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);

listview = (ListView)findViewById(R.id.mylistview);
textview = (TextView)findViewById(R.id.textview);
button01=(Button)findViewById(R.id.button01);
button01.setOnClickListener(new Button01Listener());


}

class Button01Listener implements OnClickListener{

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this,otherActivity.class);
startActivityForResult(intent, 100);
}

}

public void onActivityResult(int requestCode,int resultCode,Intent data)
{
switch (resultCode) {
case 20:

name = data.getStringExtra("name");




}
}
void Getname()
{
textview.setText(name.toString());
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
Map<String,Object> map = new HashMap<String,Object>() ;
map.put("name",name);
list.add(map);

SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.listview, new String[]{"name"}, new int[]{R.id.tv1});
listview.setAdapter(adapter);
adapter.notifyDataSetChanged();

}


}
请大家帮忙看看
...全文
评论 12
收藏 已收藏
分享
返回顶部
hellofenny
Android 80,490 成员 91,375 内容