Comments (7)
parallaxGridView.setOnItemClickListener(new setOnItemClickListener()
This doesn't seem like a good implementation of AdapterView.OnItemClickListener()
. There is no such thing as new setOnItemClickListener()
Here is an example, that's tested and it's working, of an implementation on the example project:
} else if (view.getId() == R.id.btnGrid) {
mContainer.removeAllViews();
final View v = getLayoutInflater().inflate(R.layout.include_gridview, mContainer, true);
ParallaxGridView mGridView = (ParallaxGridView) v.findViewById(R.id.view);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.v("MainActivity", position + "");
}
});
mGridView.setParallaxView(getLayoutInflater().inflate(R.layout.view_header, mGridView, false));
mGridView.setAdapter(mAdapter);
mGridView.setNumColumns(2);
}
from android-parallax-listview.
that was a typo
parallaxGridView.setOnItemClickListener(new OnItemClickListener(){
@OverRide
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Log.v("Item Clicked",position+"");
}
});
you are calling setParallaxView after setOnItemClickListener would that make any difference?
from android-parallax-listview.
this is how my code looks like:
public class LiteProfileDetailFragment extends Fragment implements, OnItemClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(
R.layout.lite_profile_detail, container, false);
getLoaderManager().initLoader(1, null, this);
initUi(root);
return root;
}
private void initUi(View view) {
gv = (ParallaxGridView) view.findViewById(R.id.parallaxGridView);
ll = new LinearLayout(getActivity());
ll.setOrientation(LinearLayout.HORIZONTAL);
bg = new ImageView(getActivity());
ll.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
name = new TextView(getActivity());
name.setLines(2);
ll.addView(bg);
ll.addView(name);
ll.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pop = popupWindowForHeader(false);
pop.showAsDropDown(v, 0, 0);
}
});
gv.setParallaxView(ll);
}
@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
// some sql query
return (loader);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
build(data) ;
lpdAdapter.swapCursor(data);
}
private void build(Cursor cursor) {
// some code
name.setText(room.name + System.getProperty("line.separator")
+ room.description);
lpdAdapter = new LiteProfileDetailAdapter(getActivity(), room);
gv.setAdapter(lpdAdapter);
gv.setOnItemClickListener(this);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
loader = null;
}
private void restart(int id) {
if (this.isVisible())
getLoaderManager().restartLoader(id, null, this);
}
public class LiteProfileDetailAdapter extends CursorAdapter {
private Profile room;
public LiteProfileDetailAdapter(Context context, Profile room) {
super(context, null, true);
this.room = room;
}
@Override
public void bindView(View convertView, Context context,
final Cursor cursor) {
ViewHolder vh = new ViewHolder();
vh.color = (LinearLayout) convertView.findViewById(R.id.color);
vh.icon = (ImageView) convertView.findViewById(R.id.icon);
vh.name = (TextView) convertView.findViewById(R.id.name);
vh.color.setBackgroundColor(Color.parseColor(room.color));
imageLoader.displayImage(cursor.getString(cursor
.getColumnIndexOrThrow(DataConstants.ICON_URL)), vh.icon);
vh.name.setText(cursor.getString(cursor
.getColumnIndexOrThrow(DataConstants.NAME)));
convertView.setTag(cursor.getString(cursor
.getColumnIndexOrThrow(DataConstants.WUID)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View convertView = LayoutInflater.from(context).inflate(
R.layout.lite_row_widget_items, (ViewGroup) null);
return convertView;
}
class ViewHolder {
public LinearLayout color;
public ImageView icon;
public TextView name;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Log.v("Item Clicked",position+"");
}
}
I simplified the code so hopefully there is no typo it again :)
from android-parallax-listview.
I don't see anything wrong with the code. There should be something wrong with anything else. I tested the method and it is in fact working. Can you check if the returned view from onItemClick
is the one you clicked or it's any other?
from android-parallax-listview.
view and parent are correct
parent comes as com.poliveira.apps.parallaxlistview.ParallaxGridView
and view as android.widget.LinearLayout which my widget item is
there are other factors that could cause the problem:
1- I have tabhhost and tab widget in my xml file with ParallaxGridView
2- I am using https://github.com/nostra13/Android-Universal-Image-Loader to load my image in ParallaxGridView's header
3- I am using cursorLoader and cursoradapter
from android-parallax-listview.
I had the same problem. Viewing the code I saw that you must to subtract the "numHeadersAndPlaceholders" cause they affect to the count of items. This is the headersCount * numberOfColumns, so:
final int numOfHeadersAndPlaceholders = mGridView.getHeaderViewCount() * getResources().getInteger(R.integer.num_columns);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Item item = items.get(position - numOfHeadersAndPlaceholders);
/* ... */
}
});
from android-parallax-listview.
Then that is a bug that should be looked at.
I just used tags to identify the row. So inside bindView I had convertView.setTag(cursor.getString(cursor .getColumnIndexOrThrow(DataConstants.WUID)));
which wuid for me is key to my sql table. Then in OnItemClickListener I used Log.v("Item Clicked",(String)view.getTag());
then I know which row in my sql table is clicked on. You can also use position instead of WUID. So in bindView it would be convertView.setTag(position)
and in OnItemClickListener Log.v("Item Clicked",(Integer)view.getTag()+"");
from android-parallax-listview.
Related Issues (10)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-parallax-listview.