0
我想將片段活動中的數據傳遞給另一個類。但是, 它會產生一個錯誤,即「構造函數Intent(new View.OnClickListener(){},Class)未定義」。Android - 構造函數未定義錯誤
與此代碼
'Intent intent = new Intent(this, WebSocket_Connector.class);'
這裏是code..how我可以通過 'ID' 的字符串值?
public class Myoffers_Fragment extends Fragment {
private final WebSocketConnection mConnection = new WebSocketConnection();
public static Fragment newInstance(Myoffers context, int pos, float scale)
{
Bundle b = new Bundle();
b.putInt("pos", pos);
b.putFloat("scale", scale);
return Fragment.instantiate(context, Myoffers_Fragment.class.getName(), b);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
return null;
}
LinearLayout l = (LinearLayout) inflater.inflate(R.layout.mf, container, false);
int pos = this.getArguments().getInt("pos");
TextView tv = (TextView) l.findViewById(R.id.text);
tv.setText("Product " + pos);
ImageButton product_photo = (ImageButton) l.findViewById(R.id.myoffer_image);
if (pos == 0) {
product_photo.setImageResource(R.drawable.myoffers_0);
product_photo.setOnClickListener(new ImageButton.OnClickListener(){
public void onClick(View v){
String id1 = "Product0";
Intent intent = new Intent(this, WebSocket_Connector.class);
intent.putExtra("KeyToAccessData", id1);
startActivity(intent);
Log.d(TAG, "Current product is : " + id1);
Log.d(TAG, id1 + "is sent to server!");
}
});
}
感謝。有用。 – user2500696
歡迎你 – Blackbelt
你可以請檢查「Android - Autobahn Websocket發送消息錯誤(NullPointerException)」的問題,如果你不介意嗎.. ..沒有人回答.. :( – user2500696