Open dhohle opened 10 years ago
can you post a small code sample, perhaps of where you are setting the OnClickListener?
Caller:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.gridview, container, false);
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView
.findViewById(R.id.container);
mGridView = (GridView) rootView.findViewById(R.id.gridView1);
if (this.thisTab != null) {
this.thisTab.addGridView(mGridView);
mImageAdapter = new NewsItemGridItemAdapter(rootView.getContext(),
this.thisTab);
mGridView.setAdapter(mImageAdapter);
}
mGridView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
final String mId = Tabs.tabSelected.getNewsItems()
.get(position).getId();
Intent detailIntent = new Intent(getActivity(),
NewsItemDetailActivity.class);
detailIntent.putExtra(
Statics.NewsItemDetailFragment_ARG_ITEM_ID, mId);
startActivity(detailIntent);
}
});
onClick works, when:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new GridView(context); // get
// layout from mobile.xml
gridView = inflater.inflate(R.layout.relative_layout, null);
final NewsItem newsItem = tab.getNewsItems().get(position);
// set value into textview
TextView textView = (TextView) gridView
.findViewById(R.id.grid_item_label);
textView.setText(Html.fromHtml(newsItem.toString()));
But not when:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
HViewHolder holder;
if (convertView == null) {
holder = new HViewHolder();
final NewsItem newsItem = tab.getNewsItems().get(position);
final String text = newsItem.toString();
final Spanned html = Html.fromHtml(text);
convertView = inflater.inflate(R.layout.flow_detail_textview, null);
holder.flowTextView = (FlowTextView) convertView
.findViewById(R.id.flow_detail);
holder.flowTextView.setText(html);
convertView.setTag(holder);
On the other hand, using
HorizontalListView horizontalListSimilar = (HorizontalListView) rootView
.findViewById(R.id.innerhlistsimilar);
horizontalListSimilar
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
final NewsItem item = (NewsItem) ((HAdapter) parent
.getAdapter()).getItem(position);
final String mId = item.getId();
final Intent detailIntent = new Intent(
getActivity(), NewsItemDetailActivity.class);
detailIntent.putExtra(
Statics.NewsItemDetailFragment_ARG_ITEM_ID,
mId);
startActivity(detailIntent);
}
});
with:
public View getView(int position, View convertView, ViewGroup parent) {
HViewHolder holder;
if (convertView == null) {
convertView = inflater.inflate(R.layout.flow_textview, null);
holder = new HViewHolder();
convertView.setTag(holder);
} else {
holder = (HViewHolder) convertView.getTag();
}
holder.flowTextView = (FlowTextView) convertView.findViewById(R.id.ftv);
final NewsItem newsItem = this.resultNewsItems.get(position);
final String summary = newsItem.toString();
Spanned html = Html.fromHtml(summary);
holder.flowTextView.setText(html);
It does work, leaving me confused... Perhaps I just overlook something :s
One, minor, or thing. Using TextView there are settings like android:autoLink="web" android:linksClickable="true" But not for FlowTextView (as far as I could tell). Do you know whether this is a major adjustment? Otherwise I just include a TextView in FlowTextView for the linking parts of the text...
Cheers,
D
I'm not sure why the behaviour would be different for GridView compared to HListView, but I think your child views may be stealing the click focus. Try adding android:focusable="false" android:focusableInTouchMode="false" to the FlowTextView
Makes no difference. Also, when I do
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<uk.co.deanwild.flowtextview.FlowTextView
android:id="@+id/flow_detail2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp" >
<TextView
android:id="@+id/text_flow"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<ImageView
android:id="@+id/grid_detail_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:contentDescription="Description" />
</uk.co.deanwild.flowtextview.FlowTextView>
</RelativeLayout>
And add a OnClickListener (or whatever listener) to FlowTextView, nothing happens... When I add a listener to either the TextView or ImageView inside, they listen. One other detail I failed ('cause I forgot) to mention. The FlowTextView is in a GridView, which is in a SwipeRefreshLayout
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="auto_fit"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
</GridView>
</android.support.v4.widget.SwipeRefreshLayout>
Which is in a
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.danielson.web.objectiveworldnews.NewsItemListActivity" >
</android.support.v4.view.ViewPager>
Do you think that could make a difference? Also, when I simply replace the FlowTextView with a TextView, the GridView listener works again. Even after setting the settings you mentioned to false, including all other items/views I found. So it appears FlowTextView is overriding something, that I'm not able to undo...
Btw, I just found that when using
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="150dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" >
<uk.co.deanwild.flowtextview.FlowTextView
android:id="@+id/flow_detail2"
android:layout_width="80dp"
android:layout_height="80dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:padding="2dp" >
<ImageView
android:id="@+id/grid_flow_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:clickable="false"
android:contentDescription="Description"
android:focusable="false"
android:focusableInTouchMode="false" />
</uk.co.deanwild.flowtextview.FlowTextView>
</LinearLayout>
The side where FlowTextView wasn't but it's parent was, the click works... (Figuring out what that means)
holder.flowTextView.setOnTouchListener(null);
try this
When I use HorizontalListView the FlowTextView works perfectly. But when I try the same on a GridView, the onClickListener is not responding