help with the transfer of data from the adapter to Activiti, so I need to honor id by pressing the button, if easier, clicking on the level of data is transferred to another level of pressed Activiti. I have a problem with the transmission, by clicking on any level gives the parameters of the first level, tell me what is wrong with me .. Adapter code:
package com.example.mygames;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
public class lvladapter extends BaseAdapter {
private Context mContext;
public tasklvl[] lvl = {
new tasklvl ("android.resource://com.example.mygames/raw/" + R.raw.son_new, "son"),
new tasklvl ("android.resource://com.example.mygames/raw/" + R.raw.trolley_new, "sona"),
new tasklvl ("android.resource://com.example.mygames/raw/" + R.raw.son_new, "sons")
};
public lvladapter(Context c) {
mContext = c;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return lvl.length;
}
@Override
public tasklvl getItem(int position) {
// TODO Auto-generated method stub
return lvl[position];
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@SuppressLint("NewApi")
@Override
public View getView(final int position, View arg0, ViewGroup arg2) {
Button button = new Button(mContext);
button.setText(String.valueOf(position+1));
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(mContext, actActionLvl.class);
Bundle args = new Bundle();
args.putSerializable("Key", getItem(position));
mContext.startActivity(intent, args);
}
});
return button;
}
}
code lvl:
package com.example.mygames;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.VideoView;
public class actActionLvl extends Activity implements OnClickListener {
Button ok;
EditText otvet;
TextView rezalt;
VideoView vv01;
tasklvl lvl;
//tasklvl lvl1 = new tasklvl ("android.resource://com.example.mygames/raw/" + R.raw.son_new, "son");
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlvl);
lvl = (tasklvl)getIntent().getSerializable("Key");
ok = (Button) findViewById(R.id.ok);
otvet = (EditText) findViewById(R.id.otvet);
ok.setOnClickListener(this);
rezalt = (TextView) findViewById(R.id.rezalt);
VideoView vv = (VideoView)this.findViewById(R.id.vv01);
Uri video = Uri.parse(lvl.geturl());
vv.setVideoURI(video);
vv.start();
OnClickListener oclBtnOk = new OnClickListener() {
@Override
public void onClick(View v) {
String otv = otvet.getText().toString();
switch (v.getId()) {
case R.id.ok:
if (lvl.proverka(otv)) {
rezalt.setText("правильно");
} else {
rezalt.setText("Неправильно");
}
break;
}
}
};
ok.setOnClickListener(oclBtnOk);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
tasklvl code :
package com.example.mygames;
import java.io.Serializable;
@SuppressWarnings("serial")
public class tasklvl implements Serializable{
private String url, otvet;
private Boolean win;
public tasklvl (String url, String otvet) {
this.url = url;
this.otvet = otvet;
this.win = false;
}
public String geturl () {
return this.url;
}
public void seturl (String u) {
this.url = u;
}
public String getotvet () {
return this.otvet;
}
public void setotvet (String o) {
this.otvet = o;
}
public Boolean getwin () {
return this.win;
}
public void setwin (Boolean w) {
this.win = w;
}
public Boolean proverka (String text) {
if (text.equalsIgnoreCase(this.getotvet())) {
return true;
}
else {
return false;
}
}
}
0 comments:
Post a Comment