Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

PDF Viewer u Androidu

[es] :: Java :: PDF Viewer u Androidu

[ Pregleda: 764 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

gojic
Indjija,Srbija

Član broj: 276886
Poruke: 28
*.dynamic.isp.telekom.rs.



Profil

icon PDF Viewer u Androidu29.04.2017. u 17:23 - pre 38 meseci
Pozdrav.

Pravim aplikaciju koja se sastoji od prve strane nakoji ce biti lista knjiga.Kada se klikne na sliku knjige korisnik ce moci da prelista,nesto kao besplatan uzorak.Dakle prvih par stranica i isto toliko poslednjih stranica.
Planirao sam to da uradim sa intentom. Dakle kad neko klikne sliku knjige pomocu click listenera i intenta se otvara nova java klasa u kojoj bi mi bio pdf fajl koji zelim da bude prikazan.Bio bi prikazan pomocu PDF VIewera.Medjutim iako nemam nikakvu run-time gresku na telefonu mi izbacuje gresku da se moja aplikacija zaustavila.

Sigurno meni logika ne valja. Ne znam ni koliko mi je sam intent problem zato sto kad stavim toast u intent , poruka se normalno prikazuje prilikom klikom na sliku knjige. Onog momenta kad stavim u onclick listener, intent da se otvori java klasa sa pdf fajlom koji zelim da prikazem na telefonu, desi se ta greska.

Ubacio sam u build grade biblioteku iz koje uzimam pdf viewer:
Code:
compile 'com.github.barteksc:android-pdf-viewer:2.3.0'


XML kod glavne stranice gde mi se nalazi lista knjiga:
Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/activity_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.dsk.android.decijisvetknjiga.MainActivity">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#3498DB">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/slika_1"
                        android:layout_width="125dp"
                        android:layout_height="175dp"
                        android:layout_margin="5dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/placeholder" />

                    <TextView
                        android:id="@+id/naziv_knjige_1"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="22dp"
                        android:layout_weight="1"
                        android:text="Naziv knjige"
                        android:textSize="16sp"
                        android:textStyle="bold|italic" />

                    <TextView
                        android:id="@+id/cena_1"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="50dp"
                        android:layout_weight="1"
                        android:text="00 RSD"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>


            </RelativeLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#3498DB">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/slika_2"
                        android:layout_width="125dp"
                        android:layout_height="175dp"
                        android:layout_margin="5dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/placeholder" />

                    <TextView
                        android:id="@+id/naziv_knjige_2"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="22dp"
                        android:layout_weight="1"
                        android:text="Naziv knjige"
                        android:textSize="16sp"
                        android:textStyle="bold|italic" />

                    <TextView
                        android:id="@+id/cena_2"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="50dp"
                        android:layout_weight="1"
                        android:text="00 RSD"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>

            </RelativeLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#3498DB">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/slika_3"
                        android:layout_width="125dp"
                        android:layout_height="175dp"
                        android:layout_margin="5dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/placeholder" />

                    <TextView
                        android:id="@+id/naziv_knjige_3"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="22dp"
                        android:layout_weight="1"
                        android:text="Naziv knjige"
                        android:textSize="16sp"
                        android:textStyle="bold|italic" />

                    <TextView
                        android:id="@+id/cena_3"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="50dp"
                        android:layout_weight="1"
                        android:text="00 RSD"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>


            </RelativeLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="#3498DB">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/slika_4"
                        android:layout_width="125dp"
                        android:layout_height="175dp"
                        android:layout_margin="5dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/placeholder" />

                    <TextView
                        android:id="@+id/naziv_knjige_4"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="22dp"
                        android:layout_weight="1"
                        android:text="Naziv knjige"
                        android:textSize="16sp"
                        android:textStyle="bold|italic" />

                    <TextView
                        android:id="@+id/cena_4"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="50dp"
                        android:layout_weight="1"
                        android:text="00 RSD"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>


            </RelativeLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#3498DB">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/slika_5"
                        android:layout_width="125dp"
                        android:layout_height="175dp"
                        android:layout_margin="5dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/placeholder" />

                    <TextView
                        android:id="@+id/naziv_knjige_5"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="22dp"
                        android:layout_weight="1"
                        android:text="Naziv knjige"
                        android:textSize="16sp"
                        android:textStyle="bold|italic" />

                    <TextView
                        android:id="@+id/cena_5"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="50dp"
                        android:layout_weight="1"
                        android:text="00 RSD"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>
            </RelativeLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="1dp" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#3498DB">


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:id="@+id/slika_6"
                        android:layout_width="125dp"
                        android:layout_height="175dp"
                        android:layout_margin="5dp"
                        android:scaleType="centerCrop"
                        android:src="@drawable/placeholder" />

                    <TextView
                        android:id="@+id/naziv_knjige_6"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="22dp"
                        android:layout_weight="1"
                        android:text="Naziv knjige"
                        android:textSize="16sp"
                        android:textStyle="bold|italic" />

                    <TextView
                        android:id="@+id/cena_6"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_marginLeft="50dp"
                        android:layout_weight="1"
                        android:text="00 RSD"
                        android:textSize="16sp"
                        android:textStyle="bold" />
                </LinearLayout>

            </RelativeLayout>

        </LinearLayout>
    </RelativeLayout>

</ScrollView>


Drugi XML kod gde mi se nalazi PDF Viewer:

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.github.barteksc.pdfviewer.PDFView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/prvi_pdf">
    </com.github.barteksc.pdfviewer.PDFView>

</LinearLayout>


Prvi java fajl gde mi se nalaze inten i onclick listeneri i intenti:
Code:
package com.dsk.android.decijisvetknjiga;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.github.barteksc.pdfviewer.PDFView;

public class MainActivity extends AppCompatActivity {


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


        ImageView imgV1 = (ImageView) findViewById(R.id.slika_1);
        ImageView imgV2 = (ImageView) findViewById(R.id.slika_2);
        ImageView imgV3 = (ImageView) findViewById(R.id.slika_3);
        ImageView imgV4 = (ImageView) findViewById(R.id.slika_4);
        ImageView imgV5 = (ImageView) findViewById(R.id.slika_5);
        ImageView imgV6 = (ImageView) findViewById(R.id.slika_6);

        imgV1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "Prva Knjiga", Toast.LENGTH_SHORT).show();
                Intent prvaKnjiga = new Intent(MainActivity.this, PrvaKnjiga.class);
                startActivity(prvaKnjiga);
            }
        });
        imgV2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "Druga knjiga", Toast.LENGTH_SHORT).show();
            }
        });
        imgV3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "Treca knjiga", Toast.LENGTH_SHORT).show();
            }
        });
        imgV4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "Cetvrta knjiga", Toast.LENGTH_SHORT).show();
            }
        });
        imgV5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "Peta knjiga", Toast.LENGTH_SHORT).show();
            }
        });
        imgV6.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(v.getContext(), "Sesta knjiga", Toast.LENGTH_SHORT).show();
            }
        });

    }

}


Drugi JAVA fajl sa PDF Viewrom:
Code:
package com.dsk.android.decijisvetknjiga;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.github.barteksc.pdfviewer.PDFView;


public class PrvaKnjiga extends AppCompatActivity{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.prva_knjiga);

        PDFView pdfView  = (PDFView)findViewById(R.id.prvi_pdf);
        pdfView.fromAsset("loops.pdf").load();
    }
}

Intent sam ubacio samo u prvi onclisk listener kao probu cim sam video gresku nije bilo potrebe da se dalje trudim dok ne prokljuvim sta dalje.
 
Odgovor na temu

[es] :: Java :: PDF Viewer u Androidu

[ Pregleda: 764 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.