私は実際にこれに対するいくつかの回答を読みましたが、クリック応答を実装している単純な方法とは大きく異なるため、onLongClick 応答を作成するために行っていることに単純なものを追加する方法があるかどうか疑問に思っています。
基本的に、すべての XML コードは次のようなステートメントで記述されています。
android:onClick="onSync"
次に、私のJavaには次のものがあります。
public void onSync(View v) {
...
Toast toast3=Toast.makeText(this, "Sync was pressed",Toast.LENGTH_SHORT);
toast3.show();
}
私がやりたいのは、ボタンが長押しされたときに呼び出される別の機能を持つことです。現在、長押しは短押しと同じアクションを引き起こします。
具体的には、次のようなルーチンにインターフェイスする方法を知りたいです。
public void onSyncLong(View v) {
...
Toast toast3=Toast.makeText(this, "Long Sync was pressed",Toast.LENGTH_SHORT);
toast3.show();
}
この問題について何か助けていただければ幸いです。XML と Jave で何をすべきかを返信で教えてくれたら最高です。本当にありがとう。
- - - - - - - - - - - - - - アップデート - - - - - - - - - - - ---
これが私のonCreateコードです:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.start_meters);
textLL = (TextView)findViewById(R.id.textLL);
textTimer = (TextView)findViewById(R.id.textTimer);
textTimeToLine = (TextView)findViewById(R.id.textTimeToLine);
Button button = (Button) findViewById(R.id.button_sync);
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
return true;
}
});
}
ボタンの XML セグメントは次のとおりです。
<Button
android:id="@+id/buttonSync"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Gun/Sync"
android:onClick="onSync"
android:textSize="@dimen/font_small"
android:background="@drawable/round_button"
android:padding="3sp"
android:longClickable="true"/>
------------最終更新----------------
作業コードは次のとおりです。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.start_meters);
textLL = (TextView)findViewById(R.id.textLL);
textTimer = (TextView)findViewById(R.id.textTimer);
textTimeToLine = (TextView)findViewById(R.id.textTimeToLine);
Button button = (Button) findViewById(R.id.buttonSync);
button.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
StartLine2.startTime = pTime + 1000*60*5;
return true;
}
});
}