我有一个ListView,我想让一些项目无法点击(因此点击不会显示任何效果),但有些是。它就像listView的一种标题/部分。
我发现可以覆盖方法public boolean isEnabled(int position)
,以便返回值false
可以使其不可触及。所以我尝试了这个:
@Override
public View getView(int position, View view, ViewGroup parent)
{
...
if ( Item should be unclickable)
{
clickable = false;
isEnabled(position);
....
}
else
{
clickable = true;
isEnabled(position);
....
}
...
}
@Override
public boolean isEnabled(int position ) {
return clickable;
}
但这不起作用。它不会影响ListView。
当我只想调用isEnabled时,我想让我的项目无法点击,那么我的listView中的所有内容都是无法点击的......
xml of listView:
<ListView
android:id="@+id/listView_playlists"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:fastScrollEnabled="true"
android:smoothScrollbar="true"
android:focusable="false"
android:drawSelectorOnTop="true"
android:gravity="top" >
</ListView>
有人能帮助我吗?
修改 代码:
@Override
public View getView(int position, View view, ViewGroup parent) {
View rview = view;
holder = null;
if (rview == null)
{
LayoutInflater inflater = context.getLayoutInflater();
rview= inflater.inflate(R.layout.row_playlist, null, true);
holder = new ViewHolder(rview);
rview.setTag(holder);
}
else
{
holder = (ViewHolder) rview.getTag();
}
if (AL_playlists.get(position).m_type.equalsIgnoreCase("header"))
{
clickable = false;
isEnabled(position);
holder.txtTitle.setText(AL_playlists.get(position).get_playlist_name());
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)holder.txtTitle.getLayoutParams();
params.setMargins(0, 10, 0, 10); //substitute parameters for left, top, right, bottom
holder.txtTitle.setLayoutParams(params);
holder.txtTitle.setGravity(Gravity.CENTER);
holder.imgAlbumart.setVisibility(View.GONE);
holder.txtArtist.setVisibility(View.INVISIBLE);
}
else
{
clickable = true;
isEnabled(position);
mArtLoader.loadBitmap(AL_playlists.get(position).get_picture_path() ,holder.imgAlbumart);
holder.txtTitle.setText(AL_playlists.get(position).get_playlist_name());
holder.txtArtist.setText(String.valueOf(AL_playlists.get(position).get_list_size()));
}
return rview;
}
@Override
public boolean isEnabled(int position ) {
if (clickable == true)
return true;
else
return false;
}
@Override
public boolean areAllItemsEnabled ()
{
return false;
}
答案 0 :(得分:0)
尝试:
ListView myListView = (ListView)findViewById(R.id.listView);
myListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> ad, View view, int pos, long arg) {
if(pos == 3) {
view.findViewById(R.id.listView).setClickable(false);
}
}
});
答案 1 :(得分:0)
试试吧
$query1 = $database->prepare("SELECT * FROM module_settings
WHERE project_token = ? AND module_id = ? ORDER BY id DESC LIMIT 1");
$query1->execute(array($page["project_token"], 2));
$idx = $query1->fetch(PDO::FETCH_ASSOC);
$idx["settings"] = json_decode($idx["settings"]);
希望这个帮助