Chakib SAFAR
Chakib SAFAR

Reputation: 66

Can't use OnClickListener on TileView

I'm using the project TileView to display big images and add markers on it, in android, it works well Except that when I put an OnClickListener on the View does not work, i use the code bellow:

public class MainActivity extends ActionBarActivity implements OnClickListener  {

TileView tileView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    tileView = new TileView(this);
    tileView.setSize( 1066, 678 );

    tileView.addDetailLevel( 1.000f, "arc/tiles/arc-%col%_%row%.png", "arc/arc.png");

    tileView.setClickable(true);
    setContentView( tileView );
    tileView.setOnClickListener(this);    
}


@Override
public void onClick(View view) {

// thing to do  

}

what should I do so OnClickListener works

Upvotes: 0

Views: 465

Answers (3)

Chakib SAFAR
Chakib SAFAR

Reputation: 66

I sent a question to the owner of the library, he helped me to solve the probleme, like oguzhand suggests, i have to use a TileViewEventListener,

the code below works well (proposed by the owner of the library TileView)

tileView.addTileViewEventListener( listener );
...
private TileViewEventListenerImplementation listener = new TileViewEventListenerImplementation(){
public void onTap( int x, int y ) {
    Log.d( "DEBUG", "tapped" );
}

}

Upvotes: 0

Mike M.
Mike M.

Reputation: 39201

TileView apparently defines a TileViewEventListener interface, and the addTileViewEventListener() method. I would suggest using those, with the interface's onFingerDown() and/or onFingerUp() methods.

Upvotes: 1

You need to get id of the view for accessing onclick

@Override
public void onClick(View view) {


    int viewId = view.getId();

    switch (viewId) {
        case R.id.button_id:
            //do smthing
            break;

        default:
            break;
    }
}

Upvotes: 0

Related Questions