小编dee*_*pak的帖子

Snackbar在片段类中不起作用

当我点击按钮时,我试图显示小吃栏视图但是当我点击按钮时它显示强制关闭错误

我在下面定义了片段类,还有错误日志.

我有片段类:

public class HomeFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_home, container, false);
        context = getActivity();
        initUI(rootView);
        return rootView;
    }

    private void initUI(View view) {

        btn= (Button) view.findViewById(R.id.btnpress);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(getView(),"SnackBAr Test" , Snackbar.LENGTH_LONG).show();
            }
        });
    }
Run Code Online (Sandbox Code Playgroud)

fragment_home.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/mainrl"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal"
        android:paddingBottom="40dp" >

            <Button
            android:id="@+id/btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:Text="PLEASE …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-activity android-design-library android-snackbar

46
推荐指数
3
解决办法
4万
查看次数

无法从缓存okHttp和retrofit加载数据

这是我的代码,我在这里调用api,并通过改造为okhttp定义缓存:

public class DemoPresenter {

    DemoView vDemoView;
    private Context mContext;

    public DemoPresenter(Context mcontext, DemoView vDemoView) {
        this.vDemoView = vDemoView;
        this.mContext = mcontext;
    }

    public void callAllProduct() {
        if (vDemoView != null) {
            vDemoView.showProductProgressBar();
        }


        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .cache(new Cache(mContext.getCacheDir(), 10 * 1024 * 1024)) // 10 MB
                .addInterceptor(new Interceptor() {
                    @Override
                    public okhttp3.Response intercept(Chain chain) throws IOException {
                        Request request = chain.request();
                        if (BasicUtility.isInternet(mContext)) {
                            request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
                        } else {
                            request = request.newBuilder().header("Cache-Control", …
Run Code Online (Sandbox Code Playgroud)

android caching retrofit retrofit2 okhttp3

11
推荐指数
1
解决办法
2046
查看次数

从特定日期获取日期,月份和年份

我想从特定日期获得日期,月份和年份.

我使用下面的代码:

 String dob = "01/08/1990";

        int month = 0, dd = 0, yer = 0;

        try {

            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
            Date d = sdf.parse(dob);
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            month = cal.get(Calendar.MONTH);
            dd = cal.get(Calendar.DATE);
            yer = cal.get(Calendar.YEAR);

        } catch (Exception e) {
            e.printStackTrace();
        }
Run Code Online (Sandbox Code Playgroud)

所以从上面的代码我得到了 month -0 , yer - 1990 and date - 8

但我想要month - 01 , date - 08 and yer - 1990.

我也定义了日期格式,但我没有从日期,月份和年份获得完美的价值.

android date android-date

5
推荐指数
1
解决办法
6074
查看次数

如何使用javascript 1分钟后刷新Repeater?

我创建了一个中继器,现在我想在每1分钟后刷新一次中继器.打击是我的代码:

 <asp:Repeater ID="gvd" runat="server">

                <ItemTemplate>
                    <tr class="gradeA">
                        <td>
                            <asp:Label ID="lblcategory" runat="server" Text='<%#Eval("Firstname")%>'></asp:Label>

                        </td>
                        <td>
                            <asp:Label ID="lblcontent" runat="server" Text='<%#Eval("Lastname")%>'></asp:Label>
                        </td>

                     </tr>
                </ItemTemplate>

            </asp:Repeater>
Run Code Online (Sandbox Code Playgroud)

它提供了完美的输出,但现在我想通过javascript刷新整个转发器,因为使用updatepanel它会增加服务器上的负载

那我怎么能通过javascript做到这一点?

.net javascript c# asp.net webforms

4
推荐指数
1
解决办法
1619
查看次数

如何在触摸图像时通过放大/缩小来全屏查看图像

我有以下imagedetails.xml布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/inLay"
        android:layout_width="wrap_content"
        android:layout_height="150dp"
        android:orientation="horizontal" >

        <HorizontalScrollView
            android:id="@+id/hsv"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:fillViewport="true"
            android:measureAllChildren="false"
            android:scrollbars="none" >

            <LinearLayout
                android:id="@+id/innerLay"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >

                <LinearLayout
                    android:id="@+id/controlled_medication"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <RelativeLayout
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent" >

                        <ImageView
                            android:id="@+id/image1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" />
                    </RelativeLayout>
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/as_needed_medication"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <RelativeLayout
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:orientation="horizontal" >

                        <ImageView
                            android:id="@+id/image2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content" />
                    </RelativeLayout>
                </LinearLayout>
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

对于这个xml文件,我写了以下代码:

public class ImageDetails extends Activity {

    LinearLayout asthmaActionPlan, controlledMedication, asNeededMedication,
            rescueMedication, yourSymtoms, yourTriggers, …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-activity

4
推荐指数
2
解决办法
7905
查看次数

如何在android中获取当前日期和时间并将其存储到字符串中

目前我正在使用以下代码:

String  currentDateTimeString = DateFormat.getDateTimeInstance()
                        .format(new Date());
Run Code Online (Sandbox Code Playgroud)

从这里我得到以下格式的输出 -

Jun 5, 2015 1:15:29 PM

但现在我想要以下面的格式输出 -

2015-06-05 08:10:40 
Run Code Online (Sandbox Code Playgroud)

它可以是12或24小时格式.

我想要当前日期时间以上日期时间格式.

我已经使用了SimpleDateFormat但是我无法使用当前日期和时间获得上述日期时间格式

那么,我怎样才能做到这一点?

android android-date

4
推荐指数
1
解决办法
2万
查看次数

AppCompatCheckBox不适用于以下API 21

我使用以下代码创建了动态复选框:

XML:

<LinearLayout
    android:id="@+id/layout_checkbox"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

的.java:

LinearLayout ll = (LinearLayout) findViewById(R.id.layout_checkbox);

ll.removeAllViews();

for (int i = 0; i < 10; i++) {

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    AppCompatCheckBox myCheckBox = new AppCompatCheckBox(getApplicationContext());
    myCheckBox.setText(i);
    myCheckBox.setTextColor(Color.parseColor("#FFFFFF"));
    myCheckBox.setHintTextColor(Color.parseColor("#FFFFFF"));
    myCheckBox.setTextSize(12);

    myCheckBox.setId(i);

    ll.addView(myCheckBox, lp);
}
Run Code Online (Sandbox Code Playgroud)

现在从上面的代码只有LOLLIPOP版本显示带有文本的复选框.对于以下LOLLIPOP版本,它仅显示Text但不显示复选框.

如果我将以下代码放在xml文件中,同样适用于所有设备:

<android.support.v7.widget.AppCompatCheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Testing"
    android:buttonTint="@color/colorAccent"/>
Run Code Online (Sandbox Code Playgroud)

但我不能在xml中定义复选框,因为我必须动态创建它.

即使setButtonTintList不在下面工作LOLLIPOP

如何在下面的LOLLIPOP版本中显示Checkbox AppCompatCheckBox

xml checkbox android android-checkbox android-appwidget

4
推荐指数
1
解决办法
4273
查看次数

如何使用iTextsharp在服务器地图路径上保存pdf

我使用以下代码生成pdf,它是完美的工作:

  string strQuery = "select * from userdata";
        SqlCommand cmd = new SqlCommand(strQuery);
        DataTable dt = GetData(cmd);

        //Create a dummy GridView
        GridView GridView1 = new GridView();
        GridView1.AllowPaging = false;
        GridView1.DataSource = dt;
        GridView1.DataBind();

        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.RenderControl(hw);

        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();

        htmlparser.Parse(sr);
        pdfDoc.Close();

        Response.Write(pdfDoc);
        Response.End();  
Run Code Online (Sandbox Code Playgroud)

它运作良好.但我能够将此pdf保存到服务器地图路径上.

我在pdfDoc.Close()之后写了下面的内容.

   String path …
Run Code Online (Sandbox Code Playgroud)

c# pdf asp.net itextsharp

3
推荐指数
1
解决办法
2万
查看次数

如何将片段变量访问到主活动类中

我有1个主要活动类和1个片段类:

我想访问片段类的变量到我的主要活动类:

Myfragment类:

public class DemoFragment extends Fragment {

Public String mydata="hello";
.. //other code
}
Run Code Online (Sandbox Code Playgroud)

主动性等级:

public class MainActivity extends ActionBarActivity {

   ..//other code
   DemoFragment df;

  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContext = this;

        df = new DemoFragment();

        String newdata = df.mydata; //access from fragment but it shows null

    }

}
Run Code Online (Sandbox Code Playgroud)

那么如何才能将片段类变量值访问到主要活动中?

android android-layout android-fragments

3
推荐指数
1
解决办法
5597
查看次数

如何从源地到目的地获得所有纬度和经度

我想从谷歌地图获得所有纬度和经度.

例如:假设我输入了源和目的地的lat和lon,并在地图上绘制路径,如下所示:

在此输入图像描述

所以现在我想要这个A源和B目的地之间的所有纬度和经度.并且所有lat和lon都必须存储在数据库中.

因此,当我跟踪我的汽车并且那辆车没有沿着这条路径行驶时,那时会触发一些动作,例如发送电子邮件等.

我正在使用asp.net c#进行开发.

那我怎么能得到所有的拉特和隆?

我正在使用下面的脚本

  <script>
        function initialize() {
            var map = new google.maps.Map(document.getElementById('map_canvas'), {
                zoom: 8,
                center: new google.maps.LatLng(22.304634, 73.161070),
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }),
       directions = new google.maps.DirectionsService(),
       displayer = new google.maps.DirectionsRenderer({
            draggable: true
        });

            displayer.setMap(map);
            directions.route({
                origin: new google.maps.LatLng(22.304634, 73.161070),
                destination: new google.maps.LatLng(23.022242, 72.548844),
                travelMode: google.maps.DirectionsTravelMode.DRIVING
            }, function (result) {
                displayer.setDirections(result);
            });
        }
        google.maps.event.addDomListener(window, 'load', initialize);
        google.maps.event.addListener(displayer, 'directions_changed', some_method);
    </script>
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net google-maps

2
推荐指数
1
解决办法
1520
查看次数