gpt4 book ai didi

java - 基于另一个 Activity 创建 'next' 按钮

转载 作者:行者123 更新时间:2023-11-30 01:34:54 25 4
gpt4 key购买 nike

我正在制作一个绘图应用程序。我有两个文件:“CatList_Activity.java”和“Draw_Activity.java”。 CatList_Activity 是带有显示所有图像的菜单的页面,通过单击一个(方法“onItemClick”),它会将我发送到页面 Draw_Activity 并显示该图像,id 是覆盖方法中的属性“position”。我想要做的是在 Draw_Activity 中创建“下一个”按钮(通过带有 onClickListener 的 imageView),它会立即将我发送到下一个图像。我的猜测是以某种方式增加 CatList_Activity 文件中的“位置”值,但我不确定该怎么做

CatList_Activity.java

public class CatList_Activity extends ActionBarActivity {
GridView grid;
private String[] arrImagesStrings;
String Foldername;
CatListAdapter adapter;
private AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.catlist_activity);
Toolbar toolbar = (android.support.v7.widget.Toolbar)
this.findViewById(R.id.toolbar);
toolbar.setTitle("");
this.setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true);

mAdView = (AdView) findViewById(R.id.adView);
mAdView.loadAd(new AdRequest.Builder().build());

grid = (GridView) findViewById(R.id.lsv_catlist);
Intent i = getIntent();
Foldername = i.getStringExtra("Folder");

arrImagesStrings = listAssetFiles(Foldername);
adapter = new CatListAdapter(CatList_Activity.this, R.layout.catlist_item, arrImagesStrings, Foldername);
grid.setAdapter(adapter);
grid.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), ""+selectedImagePath, Toast.LENGTH_SHORT).show();
//Log.e("name", ""+Foldername+"/"+arrImagesStrings[position]);
Intent intentdraw = new Intent(getApplicationContext(), Draw_Activity.class);
intentdraw.putExtra("Folder", Foldername + "/" + arrImagesStrings[position]);
startActivity(intentdraw);

}
}
}
}

Draw_Activity.java

public class Draw_Activity extends Activity {

private PaintView pv;
protected View layout;
protected int progress;
protected Dialog dialog;
protected Dialog textdialog;
private String[] arrImagesStrings;
protected float stroke = 6;
int postion;
private String fileName;
private int ColorAh = Color.BLACK;
String Foldername;
RelativeLayout re;
private AdView mAdView;
ImageView img_next;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.drawpic_activity);

mAdView = (AdView) findViewById(R.id.adView);
mAdView.loadAd(new AdRequest.Builder().build());

re = (RelativeLayout) findViewById(R.id.rell);
img_next = (ImageView) findViewById(R.id.image_next);

this.fileName = null;
super.onCreate(savedInstanceState);
this.pv = new PaintView(this);
re.addView(pv);
//setContentView(this.pv);
this.pv.togglePencil(true);
Intent i = getIntent();
Foldername = i.getStringExtra("Folder");


img_next.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
???
}
});
}
}

最佳答案

在您的 CatList_Activity 中,更改

Intent intentdraw=new Intent(getApplicationContext(),Draw_Activity.class);
intentdraw.putExtra("Folder", Foldername+"/"+arrImagesStrings[position]);

Intent intentdraw=new Intent(getApplicationContext(),Draw_Activity.class);
intentdraw.putExtra("FolderName", Foldername);
intentdraw.putExtra("position", position);
intentdraw.putExtra("images", arrImagesStrings);

在您的 Draw_Activity 中,处理 onClick 以增加位置并获得所需的路径。

Foldername=i.getStringExtra("FolderName");
position = i.getIntExtra("position", 0);
images = i.getStringArrayExtra("images");
path = Foldername + "/" + images[position];

关于java - 基于另一个 Activity 创建 'next' 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35222159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com