このようにあなたが勧めたように私は3番目のクラスを作りました!!
public class WebSocket_Connector {
private static final String TAG = "ECHOCLIENT";
public final WebSocketConnection mConnection = new WebSocketConnection();
public void connect(final String wsuri) {
Log.d(TAG, "Connecting to: " + wsuri);
try {
mConnection.connect(wsuri, new WebSocketHandler() {
@Override
public void onOpen() {
Log.d(TAG, "Status: Connected to " + wsuri );
Log.d(TAG, "Connection successful!\n");
}
@Override
public void onTextMessage(String payload) {
Log.d(TAG, "Got echo: " + payload);
}
@Override
public void onClose(int code, String reason) {
Log.d(TAG, "Connection closed.");
}
});
} catch (WebSocketException e) {
Log.d(TAG, e.toString());
}
}
}
そして、別のクラスから、文字列型「id」を渡して接続にアクセスしようとしています
public class Myoffers_Fragment extends Fragment {
private static final String TAG = "ECHOCLIENT";
public String id;
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;
}
WebSocket_Connector A = new WebSocket_Connector();
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("Position = " + pos);
ImageView product_photo = (ImageView) l.findViewById(R.id.myoffer_image);
switch(pos){
case 0:
product_photo.setImageResource(R.drawable.myoffers_0);
Log.d(TAG, "Current pos" + pos);
Toast.makeText(this.getActivity(), "Product" + pos + " is selected.", Toast.LENGTH_LONG).show();
id = "product 0";
A.mConnection.sendTextMessage(id);
break;
「A.mConnection.sendTextMessage(id);」が見えますか??? それは正しい方法ですか?