Giter Site home page Giter Site logo

Comments (26)

quangson91 avatar quangson91 commented on June 30, 2024 17

Add this param to rootView of ItemListView.
android:descendantFocusability="blocksDescendants"

This can help u.

from horizontalvariablelistview.

iwnijao avatar iwnijao commented on June 30, 2024 4

froy001, it seems there is no onClick>>ed<<Listener any more, you need to use OnItemClickListener (your_HListView.setOnItemClickedListener(...)). You doesn't need to implement onKeyEvent() method:

if(child != null && !child.hasFocusable() && inList) {
//click logic
}

I changed my child views to clickable = false and focusable = false and it work for me.

Tray it again.

from horizontalvariablelistview.

antoni-alvarez avatar antoni-alvarez commented on June 30, 2024 3

Thanks to iwnijao answer, just setting "clickable" & "focusable" to false now is working:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/item_background"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/item"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:clickable="false"
        android:focusable="false"
        android:scaleType="fitXY" />

</LinearLayout>

from horizontalvariablelistview.

soydan avatar soydan commented on June 30, 2024 1

iwnjao; I don't know whether you found a solution to your problem but I was having a similar issue and through debugging it boiled down to this line of code in the onKeyEvent() method:
if(child != null && !child.hasFocusable() && inList) {
//click logic
}

so apparently if your list item is focusable or it has a focusable view as a child, on click listeners do not work. Making the item view non-focusable solved it for me. I hope this helps.

from horizontalvariablelistview.

antoni-alvarez avatar antoni-alvarez commented on June 30, 2024 1

OnItemClickListener is not working for me, I don't understand why? With DevSmart HLV with the same item layout and the same adapter works without problem.

    hListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(it.sephiroth.android.library.widget.AdapterView<?> parent, View view, int position, long id) {

            Log.i( LOG_TAG, "Item click");
        }
    });

Please help!

from horizontalvariablelistview.

shaxzodshox avatar shaxzodshox commented on June 30, 2024 1

is android studio try to be visual studio?!!
so funny, we can insert multi listview in .Net and how about android?! when we add two listView, It's make error.

android is just for users not developers!

fuck u

from horizontalvariablelistview.

aporo001 avatar aporo001 commented on June 30, 2024

You must add clickable in xml file

from horizontalvariablelistview.

veonua avatar veonua commented on June 30, 2024

I've set focused, clicked, selection mode... in all possible combinations

but I used AdapterView.setOnItemClickListener (because of compatibility)
now when I use setOnItemClick>>ed<<Listener and it works!!

from horizontalvariablelistview.

iwnijao avatar iwnijao commented on June 30, 2024

Hi veonua, I'm facing the same problem. I've set android:clickable="true" in my layout xml file but setOnItemClickListener doesn't work.

import it.sephiroth.android.library.widget.AdapterView;
import it.sephiroth.android.library.widget.AdapterView.OnItemClickListener;
import it.sephiroth.android.library.widget.HListView;
private HListView mCategoryListView;

mCategoryListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            long id1 = id;

        }
    });

Could you show me how did you get setOnItemClickListener working?

from horizontalvariablelistview.

veonua avatar veonua commented on June 30, 2024

forget about mCategoryListView.setOnItemClickListener

use

mCategoryListView.setOnItemClickedListener(...)

it works

from horizontalvariablelistview.

iwnijao avatar iwnijao commented on June 30, 2024

I can't find a method named setOnItemClickedListener(...), maybe it was fixed to setOnItemClickListener. I updated from master and there is no setOnItemClickedListener. Did you set anything else to make it work? If I set any choise mode option, I can't click any view inside the list.

from horizontalvariablelistview.

iwnijao avatar iwnijao commented on June 30, 2024

It seems I'm missing some configuration value for HListView, I use an adapter base on BaseAdapter but I change to ArrayAdapter and even though onItemClickListener does'n work in my project. I've tested HorizontalVariableListViewDemo with a simple ArrayAdapter (no TestAdapter) and it works. I can't find what I'm missing in my project.

from horizontalvariablelistview.

iwnijao avatar iwnijao commented on June 30, 2024

You are right soydan, I had some views focusable and clickable. I had to set both properties to false, making focusable = false does'n work, I had to set clickable = false too. Thank's a lot.

from horizontalvariablelistview.

froy001 avatar froy001 commented on June 30, 2024

I have the same problem. cant find onClick>>ed<<Listener
Imported :
import it.sephiroth.android.library.widget.AdapterView;
import it.sephiroth.android.library.widget.AdapterView.OnItemClickListener;
import it.sephiroth.android.library.widget.HListView;

made damn sure I implemented this import it.sephiroth.android.library.widget.AdapterView.OnItemClickListener method. And no luck. My items don't click.

I also tried to implement @soydan with no luck

no go.

Can anybody help here??

from horizontalvariablelistview.

Sarzin avatar Sarzin commented on June 30, 2024

hi there

i have the same problem when add second listview "setOnItemClickListener" doesn't work.

I have add these in both my listview :

android:clickable="false"
android:focusable="false"
android:descendantFocusability="blocksDescendants"

i try to add "LinearLayout" and "android:layout_weight="1" " but the result of calling "setOnItemClickListener" is nothing.

i can just call "setOnItemClickListener" for "listView1" and "list_slidermenu" doesn't work.

please help me .......

this is my code:

mainActivity.xml

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">


<!-- Listview to display slider menu -->
<ListView
    android:clickable="false"
    android:focusable="false"
    android:descendantFocusability="blocksDescendants"
    android:id="@+id/list_slidermenu"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@color/list_divider"
    android:dividerHeight="1dp"        
    android:listSelector="@drawable/list_selector"
    android:background="@color/list_background"/>
<ListView
    android:clickable="false"
    android:focusable="false"
    android:descendantFocusability="blocksDescendants"
    android:visibility="invisible"
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    >
</ListView>

</android.support.v4.widget.DrawerLayout>

and myactivity.java

protected void onCreate(Bundle savedInstanceState)
{
....
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
....
}

private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@OverRide
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}

}

from horizontalvariablelistview.

quangson91 avatar quangson91 commented on June 30, 2024

you can remove all clickAble && focusable. (then try setOnLongItemClickListener)

from horizontalvariablelistview.

Sarzin avatar Sarzin commented on June 30, 2024

thank you for your replay, i try it before.

can you look at the my small sample.
link:
http://yekvip.com/twolistview.rar

I'm really confused after three days fighting with this two listview :|

from horizontalvariablelistview.

Sarzin avatar Sarzin commented on June 30, 2024

......................................................MainActivity.java........................................................

package info.androidhive.slidingmenu;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;

import info.androidhive.slidingmenu.adapter.NavDrawerListAdapter;
import info.androidhive.slidingmenu.model.NavDrawerItem;

public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;

// nav drawer title
private CharSequence mDrawerTitle;

// used to store app title
private CharSequence mTitle;

// slide menu items
private String[] navMenuTitles;
private TypedArray navMenuIcons;

private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTitle = mDrawerTitle = getTitle();

    // load slide menu items
    navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

    // nav drawer icons from resources
    navMenuIcons = getResources()
            .obtainTypedArray(R.array.nav_drawer_icons);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
            String selectedFromList =(String) (mDrawerList.getItemAtPosition(myItemInt));
            // String text = parent.getItemAtPosition(position).toString();
            TextView textView=(TextView)findViewById(R.id.textView1);
            textView.setText(selectedFromList);

            displayView(myItemInt);
            //  displayView(myItemInt);
        }
    });
    navDrawerItems = new ArrayList<NavDrawerItem>();

    // adding nav drawer items to array
    // Home
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
    // Find People
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
    // Photos
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
    // Communities, Will add a counter here
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1), true, "22"));
    // Pages
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1)));
    // What's hot, We  will add a counter here
    navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1), true, "50+"));


    // Recycle the typed array
    navMenuIcons.recycle();

    mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

    // setting the nav drawer list adapter
    adapter = new NavDrawerListAdapter(getApplicationContext(),
            navDrawerItems);
    mDrawerList.setAdapter(adapter);

    // enabling action bar app icon and behaving it as toggle button
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            R.drawable.ic_drawer, //nav menu toggle icon
            R.string.app_name, // nav drawer open - description for accessibility
            R.string.app_name // nav drawer close - description for accessibility
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        // on first time display view for first nav item
        displayView(0);
    }
}

/**
 * Slide menu item click listener
 * */
private class SlideMenuClickListener implements
        ListView.OnItemClickListener {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        // display view for selected nav drawer item
        displayView(position);
    }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // toggle nav drawer on selecting action bar app icon/title
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }
    // Handle action bar actions click
    switch (item.getItemId()) {

    default:
        return super.onOptionsItemSelected(item);
    }
}

/* *
 * Called when invalidateOptionsMenu() is triggered
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // if nav drawer is opened, hide the action items
    boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList);
    //menu.findItem(R.id.action_settings).setVisible(!drawerOpen);
    return super.onPrepareOptionsMenu(menu);
}

/**
 * Diplaying fragment view for selected nav drawer list item
 * */
private void displayView(int position) {
    // update the main content by replacing fragments
    String tmpStr10 = Integer.toString(position);
    TextView textView=(TextView)findViewById(R.id.textView1);
    textView.setText(tmpStr10);
    Fragment fragment = null;
    switch (position) {
    case 0:
        fragment = new HomeFragment();
        break;
    case 1:
        fragment = new FindPeopleFragment();
        break;
    case 2:
        fragment = new PhotosFragment();
        break;
    case 3:
        fragment = new CommunityFragment();
        break;
    case 4:
        fragment = new PagesFragment();
        break;
    case 5:
        fragment = new WhatsHotFragment();
        break;

    default:
        break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getFragmentManager();
        fragmentManager.beginTransaction()
                .replace(R.id.frame_container, fragment).commit();

        // update selected item and title, then close the drawer
        mDrawerList.setItemChecked(position, true);
        mDrawerList.setSelection(position);
        setTitle(navMenuTitles[position]);
        mDrawerLayout.closeDrawer(mDrawerList);
    } else {
        // error in creating fragment
        Log.e("MainActivity", "Error in creating fragment");
    }
}

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    getActionBar().setTitle(mTitle);
}

/**
 * When using the ActionBarDrawerToggle, you must call it during
 * onPostCreate() and onConfigurationChanged()...
 */

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    // Sync the toggle state after onRestoreInstanceState has occurred.
    mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // Pass any configuration change to the drawer toggls
    mDrawerToggle.onConfigurationChanged(newConfig);
}

}

......................................................activity_main.xml........................................................

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:clickable="false"
android:focusable="false"
>


<!-- Listview to display slider menu -->
<ListView

    android:descendantFocusability="blocksDescendants"
    android:id="@+id/list_slidermenu"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"
    android:divider="@color/list_divider"
    android:dividerHeight="1dp"        
    android:listSelector="@drawable/list_selector"
    android:background="@color/list_background"/>
<ListView

    android:descendantFocusability="blocksDescendants"
    android:visibility="invisible"
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    >
</ListView>

</android.support.v4.widget.DrawerLayout>

from horizontalvariablelistview.

Sarzin avatar Sarzin commented on June 30, 2024

is android studio try to be visual studio?!!
so funny, we can insert multi listview in .Net and how about android?! when we add two listView, It's make error.

android is just for users not developers!

from horizontalvariablelistview.

Xplouder avatar Xplouder commented on June 30, 2024

Thanks god i found this thread! I was debugging a problem similar to this for days. Thank you.

from horizontalvariablelistview.

thanhhai08sk avatar thanhhai08sk commented on June 30, 2024

It takes me almost day. Thank you all very much.
I set clickable and focusable to false and it works for me.

from horizontalvariablelistview.

veonua avatar veonua commented on June 30, 2024

use RecycleView from support library.

from horizontalvariablelistview.

Checkhino avatar Checkhino commented on June 30, 2024

hi thank you for the trick but i got always a problem i put focusable to false ans clickable to false
il work but i have switch on my expandable list view and now the state of swicth can be change because it is not clickable so do you have any solution to my problem
thank you a lot

from horizontalvariablelistview.

VishalJogiya avatar VishalJogiya commented on June 30, 2024
        android:focusable="false"

worked for me

from horizontalvariablelistview.

Aayesha-Raje avatar Aayesha-Raje commented on June 30, 2024
android:focusable="false"
android:clickable="false" dont work for me 

trying from 4 days oniTemclick listener is not working

public class CafesActivity extends AppCompatActivity {

final ArrayList<Word> word = new ArrayList<Word>();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_list);
    Button b = (Button)findViewById(R.id.button_change);
    Button b1 = (Button)findViewById(R.id.button_change);


    word.add(new Word(R.drawable.brewbrakes, "BrewBakes Cafe"));
    word.add(new Word(R.drawable.rio_la, "Rio La Cafe"));
    word.add(new Word(R.drawable.ccd, "cafe Coffee day"));
    word.add(new Word(R.drawable.cafe_blue, "Cafe Blues"));
    word.add(new Word(R.drawable.noahs_cafe, "Noahs Cafe and \nBistro"));
    word.add(new Word(R.drawable.akkis_burger, "Akki's Burger and Cafe"));
    word.add(new Word(R.drawable.big_bun, "Big Bun Cafe"));

    final WordAdapter adapter = new WordAdapter(this, word, R.color.cafes);


    final ListView listView = (ListView) findViewById(R.id.list);

    listView.setAdapter(adapter);


    listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        @Override

        public void onItemClick(AdapterView<?> parent, View v, final int position, long id) {
          if(position==1) {
              Toast.makeText(getApplicationContext(), "clicked" + position, Toast.LENGTH_LONG).show();
          }
            }
    });



}

}
sm1 help

from horizontalvariablelistview.

veonua avatar veonua commented on June 30, 2024

use RecyclerView instead. this component has no updates for 4 years

from horizontalvariablelistview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.