-4
我想知道他們是否是檢查按鈕是否被點擊的方法X次做某事。例如,我在我的android應用程序中有一個按鈕,如果用戶點擊它3次以上,我想顯示一個廣告。我的項目代碼如下。我相信他們是一種在onlcicklistener上實現它的方式,但不知道如何去做。Android按鈕點擊
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;
import com.startapp.android.publish.StartAppAd;
public class ClipAdapter extends BaseAdapter {
private StartAppAd startAppAd;
private GridActivity m_context;
private Soundboard m_soundboard;
private static LayoutInflater inflater=null;
public ClipAdapter(GridActivity c, Soundboard s) {
m_context = c;
startAppAd = new StartAppAd(m_context);
m_soundboard = s;
inflater = (LayoutInflater)m_context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return m_soundboard.getSize();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return m_soundboard.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
try {
final Clip c = m_soundboard.get(position);
View rowView;
if (c != null) {
rowView = inflater.inflate(R.layout.grid_item_layout, null);
TextView tv =(TextView) rowView.findViewById(R.id.textView);
ImageButton button=(ImageButton) rowView.findViewById(R.id.imageButton);
//Button button = new Button(m_context);
//button.setHeight(24);
tv.setText(c.getTitle());
m_context.registerForContextMenu(button);
button.setTag(c);
//button.getBackground().setColorFilter(new LightingColorFilter(0xffFFFFFF, 0xffFFFFFF));
//button.setPadding(0,0,0,0);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
m_context.play(c.getResourceId());
}
});
//return button;
return rowView;
}
}
catch (IndexOutOfBoundsException e) {
Log.e(getClass().getCanonicalName(), "No audio at position "
+ position);
}
return null;
}
}
不在主要的方法(甚至在android中是什麼?)。 'if'也進入'onClick'方法,因爲這就是執行的內容。 – zapl
@zapl我在這個活動中說主要。我爲我的誤會道歉。 –
@zapl編輯了我的答案。 –