开发者

How to get the view of something

开发者 https://www.devze.com 2023-03-31 12:53 出处:网络
I was wondering how I could get the view of an object. For example, if i have a listview lv and do lv.setOnClickListener (new ...) it will give me something like this

I was wondering how I could get the view of an object. For example, if i have a listview lv and do lv.setOnClickListener (new ...) it will give me something like this

Override public void onItemClick(AdapterView<?> arg0, **View ThisistheView**, int position, long arg3) {

If I were to have a function that accepted only listviews and an int position, how would I get that listviews view?

Thanks

Edit I开发者_如何学Python am trying to access a drawable inside a custom layout for each listview item. The only way i've been able to access it so far is like this

lv.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View listview,
                    int position, long arg3) {
                ImageView pincolor = (ImageView) listview
                        .findViewById(R.id.ivimtrackingpin);

However I am unable to access the drawable in another function of mine because I don't have the particular view.

If I try something like this private void setColor(final int position, ListView lv) { ; if(position

I always crash


Look at this example: http://appfulcrum.com/?p=351

It shows how to set a custom adapter (in this case a customSqlCursorAdapter) and access its views (the items in the list). You can do the same to other types of adapters (e.g. ArrayAdapters)

See line 36 in the CustomSqlCursorAdapter class. It is the getView method where you can perform changes on the views.


Are you wanting the listview or a particular view within it? If you know the view's id then there is findViewById() or if you want a view within the listview i'm sure there is a listview method that will return the view for a given index.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号