我有一个函数,它在SQLite数据库中的表上执行查询.我宣布一个常数:public static final String CANADA_HISTORY = "Canada's History";.这存储在一个String变量中,比方说difficulty,
我有一个问题:
Cursor c = mDb.rawQuery("select * from Questions_answers where CHAPTERS = '"+difficulty+"'" , null);
Run Code Online (Sandbox Code Playgroud)
它在撇号附近抛出异常.
Logcat输出:
I/Database( 1170): sqlite returned: error code = 1, msg = near "s": syntax error
D/AndroidRuntime( 1170): Shutting down VM
W/dalvikvm( 1170): threadid=1: thread exiting with uncaught exception (group=0x40015560)
E/AndroidRuntime( 1170): FATAL EXCEPTION: main
E/AndroidRuntime( 1170): android.database.sqlite.SQLiteException: near "s": syntax error: , while compiling: select * from Questions_answers where CHAPTERS = …Run Code Online (Sandbox Code Playgroud) 我想创建listview.我从JSON获得了价值.这里我从json到listview得到了值,但我无法获得onItemclickListener方法.为什么会发生这种情况我不知道,请帮助我编码,如下所示.
Logcat没有显示任何内容.
谢谢.
<ListView
android:id="@+id/contests_listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header"
android:focusable="true">
</ListView>
Run Code Online (Sandbox Code Playgroud)
Activity.java
public class Activites_Activity extends CheerfoolznativeActivity {
private ListView contests_listView;
private ProgressBar pgb;
ActivitiesBean bean;
ArrayList<Object> listActivities;
ListAdapter adapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
setHeader("Activites");
contests_listView = (ListView) findViewById(R.id.contests_listView);
pgb = (ProgressBar) findViewById(R.id.contests_progressBar);
listActivities = new ArrayList<Object>();
new FetchActivitesTask().execute();
}
public class FetchActivitesTask extends AsyncTask<Void, Void, Void> {
int i =0;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pgb.setVisibility(View.VISIBLE);
}
@Override
protected Void doInBackground(Void... …Run Code Online (Sandbox Code Playgroud) 在这里,我试图将一些数据从移动设备发送到服务器.首先,我必须登录服务器上的身份验证.然后在我通过POST请求发送数据后,我检查了这个相关的stackoverflow问题.HttpClient 4.0.1 - 如何释放连接?
我已经逐一尝试了所有这些方法.
1.EntityUtils.consume(实体);
2.is.close();
.response.getEntity()consumeContent(); //在那个consumeContent()中显示为Deprecated
post.abort();
这是我在pastebin链接中的详细代码,请检查一下.
这是程序流程.
首次登录称为"在此登录 我的登录请求"
登录后和发布之前的想法THIS方法被调用.
最后调用post idea方法.
但是logcat显示错误:
java.lang.IllegalStateException:无效使用BasicClientConnManager:仍然分配了连接.
确保在分配另一个连接之前释放连接
Run Code Online (Sandbox Code Playgroud)W/System.err( 2217): java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated. W/System.err( 2217): Make sure to release the connection before allocating another one. W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.conn.BasicClientConnectionManager.getConnection(BasicClientConnectionManager.java:161) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.conn.BasicClientConnectionManager$1.getConnection(BasicClientConnectionManager.java:138) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:455) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:902) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:801) W/System.err( 2217): at ch.boye.httpclientandroidlib.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:780) W/System.err( 2217): at com.rahul.cheerfoolz.api.util.postData(util.java:436) W/System.err( 2217): at com.rahul.cheerfoolz.postidea.idea.post_myidea_edit$Post_Idea.doInBackground(post_myidea_edit.java:354) W/System.err( …
这里我用checkbox/RadioButton创建自定义列表视图.我得到了这个,但我需要单一的选择.
我尝试使用它,lstvw.setChoiceMode(ListView.CHOICE_MODE_SINGLE);但它不适合我.有没有其他解决方案,请告诉我.
main.java
private ImageAdapter adapter;
private static String month[] = {"January","February","March","April","May",
"June","July","August","September",
"October","November","December"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView lstvw = (ListView) findViewById(R.id.listView);
adapter = new ImageAdapter(this, month);
lstvw.setAdapter(adapter);
lstvw.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lstvw.setOnItemClickListener(this);
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何将复选框的代码添加到适配器类中.请检查适配器类,如下所示.
ImageAdapter.class
public class ImageAdapter extends BaseAdapter{
public String title[];
public String description[];
public Activity context;
public LayoutInflater inflater;
public ImageAdapter(Activity context,String[] title) {
super();
this.context = context;
this.title = title;
this.inflater = …Run Code Online (Sandbox Code Playgroud) 当我使用getApplicationContext()那个时候eclipse给我错误create method 'getApplicationContext()'.请告诉我如何删除此错误.我也尝试使用ClassName.this那个时间错误就像change method startListening(Context) to startListening(Main)
当我使用像:measurement_index = AppSettings.getMeasureUnit(this);
然后错误像:change method getMeasureUnit(Context) to getMeasureUnit(Main)
所以请让我知道如何解决错误:
create方法'getApplicationContext()'
将方法getMeasureUnit(Context)更改为getMeasureUnit(Main)
检查我的代码.
Main.class
public class Main extends Fragment implements GPSCallback{
.......
public static Fragment newInstance(int position) {
Main f = new Main();
Bundle args = new Bundle();
...
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final ViewGroup root = (ViewGroup) inflater.inflate(R.layout.main, null);
/*Intent in = new Intent(Main.this,MainDisplay.class);
// ------------> Here …Run Code Online (Sandbox Code Playgroud) 在我的申请中,我需要将年龄限制在7-18岁之间.我想显示选择范围有限的日期选择器.
如何使用此代码DatePicker将同一任务编辑到日期选择器中
我使用下面的代码来限制年份,但是当点击"+/-"按钮时,年份可以在限制范围之上/之下更改.我希望该用户不能增加或减少日期值.
return new DatePickerDialog(this,
mDateSetListener,
mYear-7, mMonth, mDay);
Run Code Online (Sandbox Code Playgroud)
请帮助我设定7至18岁之间的出生日期限制,如果可能的话,请设置日期和月份.
另外,我如何设定最低年龄限制?
谢谢.