Added new SimpleListViewFragment for handling my ListView logic. Still a big to do. Overrode the onClick and longClick so that longpress would keep an item highlighted for sharing

master
Chris Baughman 2014-02-21 16:23:36 -05:00
parent f4b1454593
commit 616edfb5d0
5 changed files with 98 additions and 2 deletions

View File

@ -18,7 +18,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dip" android:layout_height="0dip"
android:layout_weight="1" android:layout_weight="1"
android:drawSelectorOnTop="false"/> android:drawSelectorOnTop="false"
style="@style/activated"
/>
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
style="@style/activated"
/>

10
res/values/styles.xml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light"></style>
<style name="activated" parent="AppTheme">
<item name="android:background">?android:attr/activatedBackgroundIndicator</item>
</style>
</resources>

View File

@ -0,0 +1,47 @@
package com.cmb.common;
import android.support.v4.app.ListFragment;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.view.View;
import java.util.Arrays;
import java.util.ArrayList;
import android.os.Bundle;
import com.cmb.googledorks.*;
public class SimpleListViewFragment extends ListFragment {
public static final String KEY_CONTENTS="contents";
public static SimpleListViewFragment newInstance(String[] contents) {
return(newInstance(new ArrayList<String>(Arrays.asList(contents))));
}
public static SimpleListViewFragment newInstance(ArrayList<String> contents) {
SimpleListViewFragment reslt = new SimpleListViewFragment();
Bundle args = new Bundle();
args.putStringArrayList(KEY_CONTENTS, contents);
reslt.setArguments(args);
return(reslt);
}
@Override
public void onActivityCreated(Bundle savedInstance) {
super.onActivityCreated(savedInstance);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
setContents(getArguments().getStringArrayList(KEY_CONTENTS));
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
((MainActivity)getActivity()).onListItemClick(this, position);
}
void setContents(ArrayList<String> contents) {
setListAdapter(new ArrayAdapter<String>(
getActivity(), R.layout.simple_listview_fragment, contents));
}
}

View File

@ -2,6 +2,7 @@ package com.cmb.googledorks;
import android.app.*; import android.app.*;
import android.os.*; import android.os.*;
import android.support.v4.app.FragmentActivity;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -12,11 +13,14 @@ import android.widget.AdapterView.*;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.*; import java.net.*;
import com.cmb.common.SimpleListViewFragment;
import android.content.*; import android.content.*;
import android.net.*; import android.net.*;
import android.widget.ShareActionProvider; import android.widget.ShareActionProvider;
public class MainActivity extends Activity implements Constants public class MainActivity extends FragmentActivity implements Constants
{ {
Spinner catSpin; Spinner catSpin;
ListView listV; ListView listV;
@ -51,6 +55,7 @@ public class MainActivity extends Activity implements Constants
list = dorks.getFeed(getBaseContext()); list = dorks.getFeed(getBaseContext());
adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, list); adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, list);
listV.setAdapter(adapter); listV.setAdapter(adapter);
listV.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
catSpin.setOnItemSelectedListener(new OnItemSelectedListener(){ catSpin.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override @Override
@ -163,4 +168,10 @@ public class MainActivity extends Activity implements Constants
mShare.setShareIntent(inten); mShare.setShareIntent(inten);
return inten; return inten;
} }
public void onListItemClick(SimpleListViewFragment simpleListViewFragment,
int position) {
// TODO Auto-generated method stub
}
} }