【发布时间】:2018-08-01 08:14:48
【问题描述】:
我已经创建了类似画廊的 android 应用程序,其中有一些使用 gridview 片段的图像。
功能工作正常,图像也显示在片段网格视图和图书活动中,但未显示文本(未设置文本)
这是我的片段代码:
GridView grid;
String[] web = {
"Google",
"Github",
"Instagram",
"Facebook",
"Flickr",
"Pinterest",
"Quora",
"Twitter",
"Vimeo",
"WordPress",
"Youtube",
"Stumbleupon",
"SoundCloud",
"Reddit",
"Blogger"
} ;
int[] imageId = {
R.drawable.person7,
R.drawable.person1,
R.drawable.person2,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7
};
int[] fullimg = {
R.drawable.person7,
R.drawable.person1,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7,
R.drawable.person7
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
setHasOptionsMenu(true);
View view = inflater.inflate(R.layout.fragment_status,container,false);
CustomGrid adapter = new CustomGrid(getActivity(), web, imageId, fullimg);
//CustomGrid adapter = new CustomGrid(MainActivity.this, web, imageId);
grid=(GridView) view.findViewById(R.id.grid);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// Toast.makeText(MainActivity.this, "You Clicked at " +web[+ position], Toast.LENGTH_SHORT).show();
String value=(String)grid.getItemAtPosition(i);
Intent intent=new Intent(getActivity(),Book.class);
intent.putExtra("web", web[i]);
intent.putExtra("imageId", imageId[i]);
intent.putExtra("fullimg", fullimg[i]);
startActivity(intent);
}
});
//return inflater.inflate(R.layout.fragment_status, container, false);
return view;
}
这是我想要显示文本和图像的图书活动代码 图片显示正常,但我不知道如何显示文字:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_book);
TextView textView = (TextView) findViewById(R.id.txttitle);
ImageView imageView = (ImageView)findViewById(R.id.imageView2);
//textView.setText(txttitle);
//textView.setText(web[i]);
imageView.setImageResource(getIntent().getIntExtra("fullimg", R.drawable.person7));
}
【问题讨论】:
-
所以要显示文字吗?
-
是的,我想在图书活动中同时显示文本和图像
-
也许我不明白这个问题,但你不能像拿 imageId 一样拿字符串吗? textView .setText(getIntent().getStringExtra("web"))
-
我正在对您的代码进行一些更改,我给您更新的答案
-
好的,我等你的更新
标签: android android-layout android-studio android-fragments gridview