I would like to assign value of product of two integer numbers into a hidden field already in the html document. I was thinking about getting the value of a javascript variable and then passing it on a input type hidden. I'm having a hard time to explain but this is how it should work:
<script type="text/javascript">
function product(a,b){
return a*b;
}
</script>
Run Code Online (Sandbox Code Playgroud)
above computes the product and i want the product to be in hidden field.
<input …Run Code Online (Sandbox Code Playgroud) 我想知道如何更改listView上所选项目的背景颜色.我只想更改用户点击的特定项目,这意味着如果用户点击另一个项目,它将是突出显示的项目.好吧,因为我希望它尽可能保持简单并使用默认的android listview我使用此代码:
record_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try{
for (int ctr=0;ctr<=record_items.length;ctr++){
if(i==ctr){
record_list.getChildAt(ctr).setBackgroundColor(Color.CYAN);
}else{
record_list.getChildAt(ctr).setBackgroundColor(Color.WHITE);
}
}
}
catch (Exception e){
e.printStackTrace();
}
Log.v("Selected item",record_list.getItemAtPosition(i));
}
});
Run Code Online (Sandbox Code Playgroud)
好的,这个工作正常,但问题是它很慢.现在我想知道是否有任何其他方法可以做到,它将提供与我相同的输出.
我尝试使用record_list.getSelectedView().setBackgroundColor(Color.CYAN);但它给了我一个空指针异常.
我也尝试了selector.xml,但它也没有做到这一点.此外,ListView上有一个名为listSelector的属性.如文档"Drawable用于指示列表中当前选定的项目"所述,它是可绘制的.我也相信这应该可以做到这一点,是的,它可以在我的模拟器上完成,但不是在我的Galaxy选项卡上.我也尝试了其他方法,但没有任何方法可行,因为我想要它.
我正在创建一个测试应用程序来测试使用最新的facebook SDK更新我们现有的应用程序问题是我需要获取我知道的电子邮件地址取决于用户是否在他的帐户中提供了一个.现在,我正在使用的帐户提供了一个肯定的帐户,但由于未知原因,facebook SDK仅提供user_id和帐户的全名,而不提供任何其他内容.我对此感到困惑,因为SDK3及以上版本提供了比更新的SDK4更多的信息,而且我对如何获取电子邮件感到迷茫,因为到目前为止我看到的所有答案都没有提供我的电子邮件.到目前为止,这是我的代码:
登录按钮
@OnClick(R.id.btn_login)
public void loginFacebook(){
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));
}
Run Code Online (Sandbox Code Playgroud)
LoginManager回调:
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
requestUserProfile(loginResult);
}
@Override
public void onCancel() {
Toast.makeText(getBaseContext(),"Login Cancelled", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException e) {
Toast.makeText(getBaseContext(),"Problem connecting to Facebook", Toast.LENGTH_SHORT).show();
}
});
Run Code Online (Sandbox Code Playgroud)
以及用户个人资料的请求:
public void requestUserProfile(LoginResult loginResult){
GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject me, GraphResponse response) {
if (response.getError() != null) {
// handle error
} else {
try {
String email …Run Code Online (Sandbox Code Playgroud) 我很困惑如何以一种简单的方式使用这个数组.好吧,我已经将JSON中的值传递给了List,现在我需要使用循环(并且只是循环)来检索它,但我不知道如何.尝试阅读一些答案,但我发现自己到底真的很困惑.我只是希望它变得简单,因为制作一个String数组,循环和获取数据通过使变量[index]简单,但我发现的所有答案只会让我陷入混乱.请帮忙.
您好,只想知道为Android Studio添加facebook SDK的步骤.好吧,我已经尝试在eclipse中这样做了,但这次我真的迷失了该做什么,因为facebook开发者页面中给出的步骤仍然是eclipse(https://developers.facebook.com/docs/getting-started/facebook -sdk-for-android/3.0 /)
我读了一些关于这个问题的问题,我认为它与我不熟悉的gradle结构有关.这就是我要求如何执行此操作的原因.基本上我只需要在我的应用程序中加入facebook登录,只需获取ID和用户名即可.登录持续存在直到退出,这就是全部.提前致谢.
我刚刚阅读并测试了AsyncTask,现在我需要知道如何在onPostExecute部分传递多个值.我使用JSON解析器从Web获取值,但是我从JSON获取的值是多个值,我将这些值传递给一个数组,该数组由每个获取的数据的列标题分隔,这是我应该返回它的部分用于onPostExecute使用.但据我所知,每次运行只能使用一次返回(如果我错了,请纠正我).
那么这是我的代码到目前为止:
public class GetInfo extends AsyncTask<String, Void, List<String>>{
private final String TAG = null;
InputStream is = null;
StringBuilder sb=null;
List<String> list = new ArrayList<String>();
@Override
protected List<String> doInBackground(String... url) {
String result = "";
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
//CONNECT TO DATABASE
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url[0]);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.v(TAG, "connected");
}catch(Exception e){
Log.v(TAG, "run failed");
Log.e("log_tag", "Error in http connection …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用GCM向用户发送通知,目前我还在研究如何最大化它.现在我只使用此处文档中提供的示例项目,并使用gcm-client示例来处理它.
现在使用Git中的这个项目我尝试使用应用程序创建的注册ID来推送消息,是的,它成功传递了消息.
现在问题是我卸载应用程序后.重新安装后,它将生成一个新的注册ID,其中我将它与前一个一起存储在服务器上,但我无法将之前的注册ID标记为不接收任何进一步的消息,因为当用户没有互联网时可能会发生卸载连接.之后,我发送消息到两个注册ID,这是卸载应用程序之前的ID和重新安装应用程序后的ID.发生了什么事情,我收到两个推送消息,尽管我预计它只会得到一个,因为应用程序已经更改了注册ID.
我希望应用程序可能会收到两个或更多重复的应用程序,如果我还更新了应用程序,因为正如文档中所述,注册ID可能会在更新时更改.
我可以做任何解决方法来处理这些重复的消息?
我正在尝试将我的应用程序ActionBar更新到工具栏中但我在自定义工具栏时遇到了一些问题,以显示自定义drawable.
我到目前为止尝试的是将我的xml drawable设置到工具栏中但是它会破坏整个工具栏并将菜单按钮移动到我无法正常看到的位置:
这是第一个可绘制的:
bg_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/bg_gradient" />
<item android:drawable="@drawable/icon_logo" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)
bg_gradient只是一个9patch图像渐变,与icon_logo相同.
对于我的工具栏:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@drawable/bg_actionbar"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
这个按下我的菜单按钮,左边的间距约为300dp,图标高度缩小.
现在我只是尝试将背景直接改为png图像(bg_gradient),同样的事情发生了.我也尝试在工具栏中添加一个ImageView,但同样的事情就是破坏了整个ToolBar,我又一次失去了如何进一步自定义这个工具栏.有人有想法吗?TIA.
更新:
我尝试在工具栏上添加线性布局以包含背景但仍然无法正确显示在我的结尾:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/actionBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/cherry_red"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_actionbar"/>
</android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
这是发生的事情:

此外,这是我的预期:

图标应位于中心,9patch图像为渐变,因为我在XML上遇到麻烦,在开始的中间和结束颜色上有一个百分比,而navigationIcon应该在渐变的顶部.
android android-layout android-support-library android-toolbar
目前我正在尝试为我的项目实现FragmentTabHost.我仍然对这些碎片很新,但我发现它在重用布局等方面非常好,这就是为什么我想进一步推动它.现在我阅读有关如何使用片段创建Tabs的教程,我在本教程中介绍了:
现在这个工作得很好,除了tabWidget位于我的布局之上,我希望它在底部.我发现在初始化所有选项卡后我需要设置tabWidget,所以我尝试添加这些代码:
mTabWidget = (TabWidget) findViewById(android.R.id.tabs);
mTabWidget.setBackgroundColor(Color.WHITE);
mTabWidget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
mTabWidget.setGravity(Gravity.BOTTOM);
Run Code Online (Sandbox Code Playgroud)
现在这个已经消除了分隔符并改变了颜色,但显然不会将我的Widget放在我的布局的底部.现在我该怎么做?
我还尝试编辑Tabhost xml并将TabWidget放在FrameLayout之后但没有任何反应.这是xml:
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="@+id/tabFrameLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal"
/>
</LinearLayout>
</android.support.v4.app.FragmentTabHost>
Run Code Online (Sandbox Code Playgroud)